linux command line cheatsheet

Despite the beautiful interfaces found on most modern distros, knowledge of Linux command lines is a useful tool to have. Knowing these basic shortcuts can make you more efficient and supercharge your productivity, not to mention make coding at the terminal that much easier. Regardless of your current background knowledge of Linux, you can start using this list of useful Linux commands right away.

CommandDescriptionFile CommandslsList the content of the current directory.ls -RList the subdirectories recursively.ls -aList all the content, including hidden files.ls -lList the content and its information.ls -lhList all the files and folders with file sizes in human-readable format.pwdOutput the current directory that you are in.cd folder1Change the working directory to folder1.cdReturn to the $HOME directory.cd ..Go up a directory.cd –Return to the previous directory.cp source destinationCopy source to destination.cp -r source destinationCopy a folder recursively from source to destination.mv source destinationMove (or rename) a file from source to destination.rm file1Remove file1.rm -f file1Remove file1 without prompt.rm -r folderRemove a folder and its content recursively.mkdir foldernameCreate a new folder foldername.rmdir foldernameRemove an empty folder.touch file1Create a file named “file1” in the current working directory.file file1Show the file type of file1.cat file1 file2Concatenate file1 to file 2.cat > file1Concatenate standard input to file1.less file1View and paginate file1.head file1Show first 10 lines of file1.tail file1Show last 10 lines of file1.chmod 777 fileChange file permission of file to 777.chown user:group fileChange ownership of file to user and group group.chmod -R +rwx /path/to/fileChange the read, write and execute permission bits for all files and folders in the path directory.ln -s source destinationCreate a symbolic link from source to destination.ln -f source destinationCreate a hard link from source to destination and remove and existing links between the two files.File Encryption and Compressiongpg2 -c fileEncrypt file.gpg2 file.gpgDecrypt file.gpg.tar -cf archive.tar foo barCreate archive.tar from files foo and bar.tar -xf archive.tarExtract all files from archive.tar.gzip file1Compress file1 and rename it to file1.gz.gzip -d file1.gzDecompress file1.gz.tar cvzf archive.tar.gz foo barCreate a gunzip archive named “archive.tar.gz” using the files’ foo and bar.tar xvzf archive.tar.gzExtract a gunzip archive named “archive.tar.gz” and place the contents in the current working directory.GPG Key Managementgpg2 –full-gen-keyCreate a new GPG keypair.gpg2 –list-keysList all the available GPG keys in the system.gpg2 –edit-key [gpg email]Modify the properties of a GPG key that you currently use.gpg2 –export –armor –output filename.asc [gpg email]Create an importable ASCII public key for a GPG key that you use.gpg2 –export-secret-keys –armor –output filename.asc [gpg email]Create an importable ASCII private key for a GPG key that you use.gpg2 –import filename.ascImport a keyfile to your machine’s keyring.gpg2 –gen-revoke –armor –output filename.asc [gpg email]Generate a revocation certificate for a GPG key that you currently use.User and Group Managementuseradd -G email -s /bin/bash linuxCreate a new user named “linux”, include it to the group “email” and set its default shell to bash.groupadd -g 2222 extraCreate a new system group named “extra” with a Group ID of 2222.usermod -G extra linuxAdd the existing “linux” user to the “extra” group.groupmod -n super extraRename the group “extra” to “super”.userdel linuxDelete the user “linux” in the system.groupdel superDelete the group “super” in the system.Text Manipulationsed 11q sample.txtPrint the first 11 lines of the file “sample.txt”.sed -i s/string1/string2/g sample.txtReplace every instance of the word “string1” with “string2” in the “sample.txt” file.sed -i y/string1/strings2/g sample.txtTranspose the word “strings2” to every instance of the word “string1” in the “sample.txt” file.uniq input.txtPrint all the identical lines of text in the “input.txt” file.sort -r sample.txtReverse the line order of the “sample.txt” file.sort -R sample.txtRandomize the line order of the “sample.txt” file.sort -g sample.txtArrange the lines of the “sample.txt” file by absolute numerical order.sort -d sample.txtArrange the lines of the “sample.txt” file by alphabetical order.sort -M sample.txtArrange the lines of the “sample.txt” file by month order.cut -c a,e,i,o,u sample.txtRemove all the vowel characters in the “sample.txt” file and print the result to the terminal.cut -f field1,field2 sample.txtRemove the first two Tab-separated columns in the “sample.txt” file and print the result to the terminal.tr “A-Za-z” “A-Z” < sample.txtTranslate all the letters in the “sample.txt” file to uppercase.tr -cd “[:print:]” < sample.txtDelete all the control characters in the “sample.txt” file.System Commandsuname -aShow system and kernel.unameShow distribution.mountShow mounted filesystems.lsblkList all currently attached block storage devices.lsmodList all currently installed kernel modules in the system.lspciList all currently attached PCI and PCI-E devices in the machine.lsusbList all currently attached USB-type devices in the system.dateShow system date.uptimeShow system uptime.whoamiShow your username.usersDisplay who is online.groupsPrint all the names of the groups that the current user is a part of.apropos commandPrint all the matching manpages for the string “command”.man commandShow manual for command.info commandDisplay the appropriate info page for that particular command.!!Repeat the last command.exitLog out of current session.File Searching Commandsgrep pattern filesSearch for pattern in files.grep -iCase insensitive search.grep -rRecursive search.grep -vInverted search.grep -oShow matched part of file only.locate file1Find file1.whereis commandFind binary/source/manual for command.which appLocate a command for the app.look string file1Display any lines in file1 which contain string as a prefix.Process ManagementpsShow snapshot of processes.topShow real time processes.kill pidKill process with id pid.pkill nameKill process with name name.killall nameKill all processes with names beginning name.time commandRun the “command” program and print the amount of time the program ran to standard output.Disk Spacedf -hShow free space on mounted filesystems.du -h folderShow file usage of each folder in folder.du -hc folderShow the file usage for each folder in folder and print the total file size.du -sh folderShow the total file size of folder.fdisk -lShow disks partitions sizes and types (run as root).freeShow memory and swap usage.

Image credit: Christina Morillo via Pexels

Keyword: Linux Command Line Cheatsheet

TECH'S NEWS RELATED

Skoda Karoq 2023 review: Style

What does it look like? How does it drive? How spacious is it? How easy is it to use every day? How safe is it? What’s the tech like? How much does it cost to own? Skoda Karoq – a good family 'all-rounder' medium SUV that might surprise you. ...

View more: Skoda Karoq 2023 review: Style

Porsche 911 GT3 RS (991.2, 2018-2020) review

Superb on road, spectacular on track. The ultimate naturally aspirated 911

View more: Porsche 911 GT3 RS (991.2, 2018-2020) review

OPPO Band 2 Price in Malaysia & Specs

The OPPO Band 2 has a AMOLED, 500 nits peak brightness display. It supports Bluetooth and NFC. It features 200mAh, Magnetic Charging, running on Android & IOS. The latest OPPO Band 2 price in Malaysia market starts from RM249. It is available in Midnight Black, Baby Blue colours. OPPO ...

View more: OPPO Band 2 Price in Malaysia & Specs

Xiaomi Moving Operations From India to Pakistan? Company Calls It Completely False and Baseless

A day after the court order was announced, reports of Xiaomi moving its operations from India to Pakistan started surfacing online.

View more: Xiaomi Moving Operations From India to Pakistan? Company Calls It Completely False and Baseless

Reliance Jio 5G Begins Beta Trials in Delhi and Other Cities: Users Report  Over 1Gbps Download Speed

Reliance Jio launched beta tests for 5G services on October 6 in the national capital. Check out more information here.

View more: Reliance Jio 5G Begins Beta Trials in Delhi and Other Cities: Users Report  Over 1Gbps Download Speed

Moto E32 with 5000mAh battery makes an entry in the Indian market

Motorola has launched yet another smartphone, Moto E32, in the country. The best part is that it ships with decent features like a high-resolution camera and a monstrous battery at a price of around Rs 10,000. The smartphone has a shiny rear panel with the Moto logo in the ...

View more: Moto E32 with 5000mAh battery makes an entry in the Indian market

Mercedes-Benz EQS 580 First Drive Review | Future S-Class In Present? | The First Impression | Oct

Oct 2022: V3Cars reviews the Mercedes-Benz EQS 580 electric car to find out how it performs in the real world. In this video, we not only tell you about its exterior, interior, features and range, but also give you an idea about its comfort and whether you can consider ...

View more: Mercedes-Benz EQS 580 First Drive Review | Future S-Class In Present? | The First Impression | Oct

Sony Xperia 10 IV review: One compromise too many

Good, but not quite good enough

View more: Sony Xperia 10 IV review: One compromise too many

Windows Resource Protection Unable to Fix Corrupt Files: 5 Fixes to Try

Pixel 7: facial recognition is finally available but there is a catch

Core i9-13900K beats Ryzen 7000 in overclocking battle after Intel chip hits 8.2 GHz

Logitech Lift Mouse review

Beelink SEi11 Pro Mini PC review

King of the Couch: The Best Local Multiplayer Games for PS5 and Xbox Series

Audi India Sales Q3 2022 At 1,182 Units – 6.5% Growth YoY

This Popular iOS 16 Feature is Draining Battery on iPhones When Enabled

A Look Into the Future: Oppo Reno 9, Reno 9 Pro Specifications Leaked! 

What makes the GeForce RTX 40 series go so fast?

Explore serene surroundings in Paper Flight – Super Speed Dash

20 Best Minecraft Weapons and Gun Mods

OTHER TECH NEWS

;