Linux-More commands

To show the full path of shell commands found in your path
     which <command name>
          eg: which grep
               //output like: /bin/grep

To locate the program, source code, and manual page for a command
     whereis <command name>
                                 
To search for files anywhere on the file system
     locate <keyword to search>
           //find all files and directories that contain the keyword

To search for files matching certain patterns
     find <directory name> <pattern to search>
           eg: find . -name \*mp3
           //starts searching in the current directory “.” and all
subdirectories, looking for files with “mp3” at the end of their
names


To list currently running process
     ps
 
To list all process in the system
     ps -aux
 
To show who is logged on and what they are doing
     w
     who
 
To view the name of current user
     whoami
 
To view the user details
     finger
 
To view host name
     hostname
 
To set host name
     hostname -a <new host name>
 
To print your user-id and group id's
     id
 
To get report on file system disk space usage
     df
In MB
     df -h
 
To view disk usage in a particular directory
     du
 
To view summary
     du -s
In MB
     du -h
                              
To display CPU processes in a full-screen GUI
     top
     // type “Q” to quit
 
To display amount of free and used memory in the system
     free
 
To display information about your CPU
     cat /proc/cpuinfo
 
To display lots of information about current memory usage
     cat /proc/meminfo
 
To print system information to the screen
     uname -a
 
To print kernel version
     uname -r
 
To display the size of a file
     wc -l
In bytes
     wc -m
In char
     wc -c
In word count
     wc -w
 
To change permission to a file/directory
     chmod [-R] <permissions> <file name/directory name>
           eg: chmod 754 one.txt
           eg: chmod -R 777 /home/songs/
{
     read r=4; write w=2; execute x=1
     Owner      Group     Others
     rwx        r-x       r--
     7          5         4
}
 
To change ownership of a file/directory
     chown [-R] <user name> <file name/directory name>
           eg: chown dhanoop one.txt
           eg: chown -R dhanoop /home/songs/
              
 
To search a file for a particular pattern
     grep [-R] <word to search> <file name/directory name>
           eg: grep science science.txt
                //case-sensitive search
           eg: grep -i science science.txt
                //case-insensitive search
           eg: grep -i ‘spinning top’ science.txt
                //multiword search
           eg: grep -R passwd /etc/
                //search in directory
 
To clear the screen
     clear
 
To display text on screen
     echo “<text to display>”
           eg: echo “Hello”
 
To print a file or program output
     lpr <file name>
           eg: lpr mp3files.txt
     <command> | lpr
           eg: ls -la | lpr
 
To sort a file or program output
     sort
           eg: sort mp3files.txt
 
To switch user
     su <user name>
           //to switch to a particular user account
     su
           //to switch to root account
     su -
           //to switch to root, and log in with root's environment
 
To give an alias name to a command for ease of use
     alias <name>=”<command>”
           eg: alias list=”ls -l”
 
To display last logins of user
     last
 
To display the name of currently working terminal
     tty
 
To block a user
     passwd -l <user name>
 
To unblock a user
     passwd -u <user name>
 
To add a user account
     useradd [options] <username>
 
With specified home directory
     useradd -d <home directory> <user name>
 
With specified shell
     useradd -s <shell> <user name>
 
With specified initial group
     useradd -g <initial group> <user name>
 
With specified expiry date
     useradd -e <YYYY-MM-DD> <user name>
 
To lock/unlock a user account
     usermod [-L or -U] <user name>
 
To delete a user account
     userdel [-r] <user name>
 
To restart the system
     shutdown -r now
          //without delay
 
To turn off the system
     poweroff
 
To reboot the system
     reboot
 
To halt the system
     halt
 
To mount a file system or media
     mount <source> <destination>
          eg: mount /dev/sda1 /mnt
                //mounting first partition of first SATA hard disk
             
          eg: mount /dev/hdb3 /mnt
                //mounting third partition of second hard disk
 
To umount a file system or media
     umount <file system/media>
          eg: umount /mnt
 
To view IP address
     ifconfig
 
To edit IP address temporarily
     ifconfig -a etho <ipaddress>
 
To view partitions and file systems
     fdisk -l
          //view line by line
 
To print selected columns in a file
     cut -c <column range> <file name>
          eg: cut -c 3-5 sem.txt
 
To print particular fields
     awk ‘{ print $<field number> }’ <file name>
          eg: awk ‘{ print $2 }’ sem.txt
                //prints second field
          eg: awk ‘{ print $1 $3 }’ sem.txt
                //prints first and third fields
 
To know the shell
     echo $SHELL
          //the symbol “$” precedes every user or system variable.
          All system variables are BLOCK lettered.
 
To know the home directory
     echo $HOME
 
To print the calendar
     cal
          //prints calendar of current month
     cal <YYYY>
          eg: cal 2010
                //prints calendar of specified year
             
To print the date
     date
 
To temporarily switch to root to execute a single command
     sudo <command>
          eg: sudo ifconfig -a eth0 192.168.1.101
 
To run an executable file
     sh <file name>
          eg: sh new\ file
                //”\ “ denotes white space
     ./<file name>
          eg: ./new\ file
 
To view command history
     history
 
To re execute last command
     !!
 
To execute nth command in history
     !n
          eg: !444
                //executes 44th command in the history
 
To re execute last command that starts with specified character
     !<char>
          eg: !s
              //executes the last command that starts with letter “s”
 
To repeat the last command changing old character to new character
     ^old^new
          eg: ^l^m
                //let “wc -l” be the last command
                     now “wc -m” will be executed

Signals to a process
To list all signals
     kill -l
To kill a process
     kill <process id>                                   
To terminate a process
     kill -9 <process id>
To normally exit a process
     kill -15 <process id>

To login remotely to a system
     ssh [<user name>@]<ip address>
          eg: ssh dhanoopbhaskar@192.168.1.101
 
To execute a command on remote system through remote login
     ssh [<user name>@]<ip address> <command>
          eg: ssh dhanoopbhaskar@192.168.1.101 df -h
               //executing “df -h” remotely
 
To copy file from a remote system
     scp [-r] <source> <destination>
          eg: scp /home/a.c dhanoopbhaskar@192.168.1.101:/home/

Post a Comment

0 Comments