-
LINUX- CHEAT SHEET
_System Based Commands
#unameDisplays Linux system information#uname -rDisplays kernel release information#uptimeDisplays how long the system has been running#hostnameShows the system hostname#hostname -iDisplays the IP address of the system#last rebootShows system reboot history#dateDisplays current system date and time#whoamiDisplays who you are logged in as#finger usernameDisplays information about the user_Hardware Based Command
#lshwDisplays information about system’s hardware configuration#lsblkDisplays block devices related information#free -mDisplays free and used memory in the system (-m indicates memory in MB)_Users Management Commands
#idDisplays the details of the active user e.g. uid, gid, and groups#lastShows the last logins in the system#whoShows who is logged in to the system#groupadd "pink"Adds the group ‘pink’#adduser "rajni"Adds user ‘rajni’#userdel "rajni"Deletes user ‘rajni’#usermodUsed for modifying user information_File Commands
#ls -alLists files – both regular & hidden files and their permissions#pwdDisplays the present working directory pathmkdir 'pink'Creates a new directory named ‘pink’#rm file_nameRemoves a file#rm -f filenameForcefully removes a file#rm -r directory_nameRemoves a directory recursively#rm -rf directory_nameRemoves a directory forcefully and recursively#cp file1 file2Copies the contents of file1 to file2#cp -r dir1 dir2Recursively Copies dir1 to dir2. dir2 is created if it does not exist#mv file1 file2Renames file1 to file2#ln -s /path/to/file_name link_nameCreates a symbolic link to file_name#touch file_nameCreates a new file#cat > file_namePlaces standard input into a file#more file_nameOutputs the contents of a file#head file_nameDisplays the first 10 lines of a file#tail file_nameDisplays the last 10 lines of a file#gpg -c file_nameEncrypts a file#gpg file_name.gpgDecrypts a file#wcPrints the number of bytes, words and lines in a file#xargsExecutes commands from standard input_Process Related Commands
#psDisplay currently active processes#ps aux | grep 'telnet'Searches for the id of the process ‚telnet‘#pmapDisplays memory map of processes#topDisplays all running processes#kill pidTerminates process with a given pid#killall procKills / Terminates all processes named proc#pkill process-nameSends a signal to a process with its name#bgResumes suspended jobs in the background#fgBrings suspended jobs to the foreground#lsofLists files that are open by processes_File Permission Commands
chmod octal filenameChange file permissions of the file to octalExample
#chmod 777 peep.txtSet rwx permissions to owner, group and everyone#chmod 755 peep.txtSet rwx to the owner and r_x to group and everyone#chmod 766 peep.txtSets rwx for owner, rw for group and everyone#chown owner user-fileChange ownership of the file#chown owner-user:owner-group file_nameChange owner and group owner of the file#chown owner-user:owner-group directoryChange owner and group owner of the directory_Network Commands
#ip addr showDisplays IP addresses and all the network interfaces#ip address add 192.160.0.1/24 dev eth0Assigns IP address 192.168.0.1 to interface eth0#ifconfigDisplays IP addresses of all network interfaces#ping hostping command sends an ICMP echo request to establish a connection to server#whois domainRetrieves more information about a domain name#dig domainRetrieves DNS information about the domain#host google.comPerforms an IP lookup for the domain name#hostname -iDisplays local IP address#wget file_nameDownloads a file from an online source#netstat -pnltuDisplays all active listening ports_Compression/Archives Commands
#tar -cf peep.tar peep<:code>Creates archive file called ‚peep.tar‘ from file ‚peep‘#tar -xf peep.tarExtract archive file ‚peep.tar‘#tar -zcvf peep.tar.gz source-folderCreates gzipped tar archive file from the source folder#gzip fileCompression a file with .gz extension_Install Packages Commands
#rpm -i pkg_name.rpmInstall an rpm package#rpm -e pkg_nameRemoves an rpm package#dnf install pkg_nameInstall package using dnf utility_Search Commands
#grep 'pattern' filesSearch for a given pattern in files#grep -r pattern dirSearch recursively for a pattern in a given directory#locate fileFind all instances of the file#find /home/ -name "index"Find file names that begin with ‚index‘ in /home folder#find /home -size +10000kFind files greater than 10000k in the home folder_File Transfer Commands
#scp file1.txt server2/tmpSecurely copy file1.txt to server2 in /tmp directory#rsync -a /home/apps /backup/Synchronize contents in /home/apps directory with /backup directory_Disk Usage Commands
#df -hDisplays free space on mounted systems#df -iDisplays free inodes on filesystems#fdisk -lShows disk partitions, sizes, and types#du -shDisplays disk usage in the current directory in a human-readable format#findmntDisplays target mount point for all filesystems#mount device-path mount-pointMount a device_Directory Traverse Commands
#cd ..Move up one level in the directory tree structure#cdChange directory to $HOME directory#cd /test Change directory to /test directory