gelanivishal
4/29/2017 - 6:24 AM

Linux Commands

Linux Commands

Linux Commands

File CommandsFile Commands

  • ls - directory listing
  • ls -al - Formatted listing with hidden files
  • cd dir - change directory to dir
  • cd - change to home
  • pwd - show current directory
  • mkdir dir - create directory dir
  • rm file - delete file
  • rm -r dir - delete directory dir
  • rm -f file - force remove file
  • rm -rf dir - remove directory dir
  • cp file1 file2 - copy file1 to file2
  • mv file1 file2 - rename file1 to file2
  • ln -s file link - create symbolic link 'link' to file
  • touch file - create or update file
  • cat > file - place standard input into file
  • more file - output the contents of the file
  • less file - output the contents of the file
  • head file - output first 10 lines of file
  • tail file - output last 10 lines of file
  • tail -f file - output contents of file as it grows

SSH

  • ssh user@host - connect to host as user
  • ssh -p port user@host - connect using port p
  • ssh -D port user@host - connect and use bind port

Installation

  • ./configure
  • make
  • make install

Network

  • ping host - ping host 'host'
  • whois domain - get whois for domain
  • dig domain - get DNS for domain
  • dig -x host - reserve lookup host
  • wget file - download file
  • wget -c file - continue stopped download
  • wget -r url - recursively download files from url

System Info

  • date - show current date/time
  • cal - show this month's calendar
  • uptime - show uptime
  • w - display who is online
  • whoami - who are you logged in as
  • uname - a - show kernel configure
  • cat /proc/cpuinfo - cpu info
  • cat /proc/meminfo - memory information
  • man command - show manual for command
  • df - show disk usage
  • du - show directory space usage

SearchingSearching

  • grep pattern files - search for pattern in files
  • grep -r pattern dir - search recursively for pattern in dir
  • command I grep pattern - search for for pattern in the output of command
  • locate file - find all instances of file

Process management

  • ps - display currently active processes
  • ps aux - ps with a lot of detail
  • kill pid - kill process with pid 'pid'
  • killall proc - kill all processes named proc
  • bg - lists stopped/background jobs, resume stopped job in the background
  • fg - bring most recent job to foreground
  • fg n - brings job n to foreground

File PermissionsFile Permissions

chmod octal file - change permisssion of file 4 - read(r) 2 - write(w) 1 - execute(x) order :- owner/group/world eg: chmod 777 - rwx for everyone chmod 755 - rw for owner, rx for group/world

CompressionCompression

  • tar cf file.tar files - tar files into file.tar
  • tar xf file.tar - untar into current directory
  • tar tf file.tar - show contents of archive tar flags: c - create archive j - bzip2 compression t - tables of contents k - do not overrite x - extract T - files from file f - specifies filename w - ask for confirmation z - use zip/gzip v - verbose
  • gzip file - compress file and rename to file.gzip
  • gzip -d file.gz - decompress file.gz
  • tar -czvf name-of-archive.tar.gz /path/to/directory-or-file - Compress an Entire Directory or a .tar.gz Single File tar.gz flags: c - Create an archive. z - Compress the archive with gzip. v - Display progress in the terminal while creating the archive, also known as “verbose” mode. The v is always optional in these commands, but it's helpful. f - Allows you to specify the filename of the archive.
  • tar -xzvf archive.tar.gz -C /destination - Extract an Archive
  • zip -r file.zip folder/ -x *media/* *.zip *.sql - Exclude zip direcory and file

Shortcuts

  • ctrl+c - halts current command
  • ctrl+z - stops current command
  • fg - resume stopped command in foreground
  • bg - resume stopped command in background
  • ctrl+d - log out of current session
  • ctrl+w - erases one word in current lines
  • ctrl+r - reverse lookup of previous commands

Various directories

  • /bin/ : This contains commands used by a regular user.
  • /boot/ : The files required for the operating system startup are stored here.
  • /cdrom/ : When CD-ROM is mounted, the CD-ROM files are accessible here.
  • /dev/ : The device driver files are stored in this folder. These device driver files will point to hardware-related programs running in kernel.
  • /etc/ : This folder contains configuration files and startup scripts.
  • /home/ : This folder contains a home folder of all users except the administrator.
  • /lib/ : The library files are stored in this folder.
  • /media/ : External media such as a USB pen drive is mounted in this folder.
  • /opt/ : The optional packages are installed in this folder.
  • /proc/ : This contains files which give information about kernel and every process running in OS.
  • /root/ : This is the administrators home folder.
  • /sbin/ : This contains commands used by the administrator or root user.
  • /usr/ : This contains secondary programs, libraries, and documentation about user-related programs.
  • /var/ : This contains variable data such as http, tftp, and similar other.
  • /sys/ : This dynamically creates the sys files