USEFUL LINUX COMMANDS

USEFUL LINUX COMMANDS

File Management : 

  1. ls  –  To list files
  • ls -l   > Display long list files
  • ls -la > Shows long list files including hidden files
  • ls -ltr > Long list files and sort by modification time. oldest placed first.
  1. less – for viewing files
  • Wants to view longer files you can use less command. 
  • It will pause after displaying screen of context
  • press q to return to the shell
  1. cat – Display the content of file
  • Cat command used to read the file or it displays all contents of file on screen
  1. head -Displays top 5 lines of file
  •  head -n 10 filename   > Displays first 10 line of file
  1. tail – Display last 10 lines of file
  • tail -f /var/log/maillog  >  to monitor the incoming log in runtime
  1. more – it is similar to less command But for scroll down you must use SPACE
  2. unique – Displays a file skips duplicate lines. It does not change original file
  3. file – Identifies the content of file
  4. cp – (copy) this makes a copy of file
  • cp source-file destination (eg. cp /root/file1 /var/dir/) This command copied content from file to /var/dir directory
  • if the destination file exists cp command will overites it.
  1. mv – rename and for move the file
  • mv existing-file-name new-file-name  > to rename the file
  • mv /var/file1 /etc/dir > this command move file1 to /etc/dir directory
  1. grep – to search in file contents
  • The grep utility searches through one or more files to see whether any contain a specified string of characters.
  • This utility does not change the file it searches but simply displays each line that contains the string.
  • eg : grep error /var/log/maillog > it will search error word in file maillog
  1. mkdir – This command creates directory
  2. touch – this command to create empty file
  3. pwd  – Shows the working directory path.

Find Directories and files:

  1. which – Shows full path of command eg . which cat  > /usr/bin/cat
  2. whereis – Shows the path of program 

eg. whereis sshd > sshd: /usr/sbin/sshd /usr/share/man/man8/sshd.8.gz

  1. find – it will search for file or directory it depends on option given by user

eg. find / -type f  -name hhtpd  > displays file named httpd under / directory

Check System information:

  1. uptime – It shows running status of machine in single file
  • Time the machine has been running
  • number of users logged in
  • the load average (it will be past 1, 5 , 15 minutes)
  1. free – (free -m) Displays the amount of RAM(Physical) and the swap memory . it display columns for used and free memory
  2. lshw – This is small tool to display detailed information of hardware configuration of the machine 
  3. hwinfo – It can be used to view log which are used for support
  4. lscpu – Display CPU information path is (/proc/cpuinfo)
  5. lspci – Displays information about PCI buses
  6. uname – Displays system information

Check User Information:

  1. users – Shows currently logged in users into the current host
  2. who – This will displays users who logged in the local system
  3. finger – Displays entry of each user currently logged into system
  4. last – (last -a) Displays list of users logged in and out 
  5. whoami – Displays username of current user id
  6. id – displays user and group IDs
  7. w – Displays the same as Uptime command

Manage system Processess

  1. top – This command displays  real time view of running system . Shows threads managed by the linux kernel
  2. ps – Displays information of active processes 
  3. nice – this effects on process scheduling 
  4. kill – This command kills the specific process
  5. vmstat – Shows the information about processes, memory, paging, block io , traps, disks, and cpu activity
  6. iostat – this command is used for monitoring system input output device loading
  7. crond – this service used to execute scheduled commands 

using crontab -e set the time to execute the command