Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
118 views

Linux Commands Cheat Sheet - LinuxForDevices

This article provides a cheat sheet of common Linux commands organized into sections such as files and directories, variables and environment, execution and processes, networking, and system administration. It lists commands like cd, ls, cat, cp, mkdir, and grep for files and directories, echo and env for variables, ps and kill for processes, curl and wget for networking, and journalctl, systemctl, and shutdown for system administration. The cheat sheet is meant to summarize commonly used commands and encourage further reading of detailed man pages.

Uploaded by

Alain Arana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
118 views

Linux Commands Cheat Sheet - LinuxForDevices

This article provides a cheat sheet of common Linux commands organized into sections such as files and directories, variables and environment, execution and processes, networking, and system administration. It lists commands like cd, ls, cat, cp, mkdir, and grep for files and directories, echo and env for variables, ps and kill for processes, curl and wget for networking, and journalctl, systemctl, and shutdown for system administration. The cheat sheet is meant to summarize commonly used commands and encourage further reading of detailed man pages.

Uploaded by

Alain Arana
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Man pages 

are the authoritative source of information for specific Linux commands.


However, seldom do these man pages include practical examples for the commands that
might save some time for the user. Here, in this article, I give you the cheat sheet of Linux
commands. Let us know in the comments which ones you already knew and if you
discovered something new.

Table of Contents
1. Cheat Sheet for Linux commands
1. Files and directories
2. Variables and environment
3. Execution and processes
4. Networking
5. System Administration
6. Package Manangement
2. Further …

Cheat Sheet for Linux commands


For brevity, I have divided this Linux commands cheat sheet into sections. All the
commands in a section are often used in conjunction with the other Linux commands in the
section. That said, you might also find yourself using a combination of commands in the
different sections. That illustrates the power of Linux and the composability of these
programs.
Files and directories

cd / Change directory to the root of the filesystem.

cd target Change directory to the targetdirectory.

cd ~ Change directory to the home directory of the


user.

ls -l Long listing, displays file ownership and


permissions.

ls -ltr Long listing, but in reverse order of time.


Gives the newest files at the bottom.

cat /etc/system-release Displays the contents of the system-release


file – which distro and flavor you are running.

cat longfile.txt | more View a long file page by page.

cp source_file.txt target_file.txt Copies a specific file

cp -r ~/source_dir ~/target_dir Copies all files and sub-directories


recursively.

cp /etc/apt/sources.{d,d.backup} Create a backup of sources.d file without


having to type the full path of the file twice!

mkdir my_directory Make a directory with the name


of my_directory.

touch my_file Create a file with the name of my_file.


mv source_file target_file Move a file or a directory.

mv my_document.{txt,file} Rename a file


from my_document.txt to my_document.fi
le

grep -i doctor $(find . -name *.txt Find the string “doctor” in all the .txt files.
-print)

Variables and environment

echo $PATH Displays the PATH environment variable

env Displays all ENV variables

export PATH=$PATH:/anotherdir Adds “anotherdir” to your PATH, just for


your current session.

source ~/.bashrc Reloads .bashrc file. Required if new


variables were added or old ones modified
in .bashrc file and it is required that
changes take effect without restarting the
shell.

Execution and processes

./runmyprogram Execute a program or shell script in your


current working directory (pwd).

./runmyprogram & Execute a program or shell script as a


background task.

ps -ef Displays information about a selection of the


running processes.
ps -ef | grep thisprogram Find a particular process by name. Here,
find thisprogram.

top or htop Displays a real-time interactive list of running


processes.

kill -9 pid Kill the process with PID as pid.

kill -9 -1 Kill all processes it can kill. Forces a logout.

whereis executable Where all places can the executable be


found in the PATH?

which executable Which executable among all in PATH is


executed?

Networking

ip -4 a Shows the IPv4 address for all NICs.

curl https://ifconfig.me/ Fetch your external IP Address.

curl Retrieve the content (HTML)


https://www.linuxfordevices.com from https://www.linuxfordevices.com

wgethttps://someurl.com/somefile.ta wget is a useful utility for downloading files


r.gz from any website.

sudo netstat -pant | grep LISTEN Lists the various in-use TCP ports and the
processes using it.

sudo netstat -pan | grep 80 Lists the process listening on port 80.
System Administration

journalctl -b -p err Display all errors since the last boot.

systemctl status foo.service Check the status of foo.service

systemctl start/restart/stop Start/restart/stop foo.service


foo.service

systemctl enable/disable Enable/disable a service to startup on boot.


foo.service

shutdown now Shuts down the system immediately.

shutdown +4 Shut down the system but after 4 minutes.

reboot Performs a soft reboot.

Package Manangement

sudo apt install package-name Install a package on Debian/Ubuntu based


systems.

sudo dnf install package-name Install a package on RedHat based(Fedora,


CentOS) systems.

Further …
Although this Linux commands cheat sheet provides you with the most used commands,
it’s worthwhile to sit down and read the man pages of individual commands. You might
have an obscure problem but going through the man pages, you might stumble upon your
required solution. So, do read the man pages in conjunction with this cheatsheet. They’re
extremely useful.

You might also like