Linux Commands
ls - directory listingls -al - Formatted listing with hidden filescd dir - change directory to dircd - change to homepwd - show current directorymkdir dir - create directory dirrm file - delete filerm -r dir - delete directory dirrm -f file - force remove filerm -rf dir - remove directory dircp file1 file2 - copy file1 to file2mv file1 file2 - rename file1 to file2ln -s file link - create symbolic link 'link' to filetouch file - create or update filecat > file - place standard input into filemore file - output the contents of the fileless file - output the contents of the filehead file - output first 10 lines of filetail file - output last 10 lines of filetail -f file - output contents of file as it growsssh user@host - connect to host as userssh -p port user@host - connect using port pssh -D port user@host - connect and use bind port./configuremakemake installping host - ping host 'host'whois domain - get whois for domaindig domain - get DNS for domaindig -x host - reserve lookup hostwget file - download filewget -c file - continue stopped downloadwget -r url - recursively download files from urldate - show current date/timecal - show this month's calendaruptime - show uptimew - display who is onlinewhoami - who are you logged in asuname - a - show kernel configurecat /proc/cpuinfo - cpu infocat /proc/meminfo - memory informationman command - show manual for commanddf - show disk usagedu - show directory space usagegrep pattern files - search for pattern in filesgrep -r pattern dir - search recursively for pattern in dircommand I grep pattern - search for for pattern in the output of commandlocate file - find all instances of fileps - display currently active processesps aux - ps with a lot of detailkill pid - kill process with pid 'pid'killall proc - kill all processes named procbg - lists stopped/background jobs, resume stopped job in the backgroundfg - bring most recent job to foregroundfg n - brings job n to foregroundchmod 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
tar cf file.tar files - tar files into file.tartar xf file.tar - untar into current directorytar 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 - verbosegzip file - compress file and rename to file.gzipgzip -d file.gz - decompress file.gztar -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 Archivezip -r file.zip folder/ -x *media/* *.zip *.sql - Exclude zip direcory and filectrl+c - halts current commandctrl+z - stops current commandfg - resume stopped command in foregroundbg - resume stopped command in backgroundctrl+d - log out of current sessionctrl+w - erases one word in current linesctrl+r - reverse lookup of previous commands/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