Linux Command Line
Linux Command Line
230
SHARES
Therefore, we’ve prepared this essential Linux command line cheat sheet to help you get
familiar with Linux security commands categorized by the scope of their actions. We’re
confident that this compilation can help you master Linux quickly.
Feel free to download a copy of this cheat sheet here and scroll down to find the
commands you need today.
Search our Linux Command Line cheat sheet to find the right cheat for the term you're
looking for. Simply enter the term in the search bar and you'll receive the matching
cheats available.
Essential Commands
We recommend that you memorize these commands. You’ll need them the most when
operating Linux.
File Management
In the following commands: X may refer to a single file, a string containing a wildcard
symbol referring to a set of multiple files, e.g., file*.txt, or the stream output of a
piped command (in which case the syntax would be X | command instead
of command X); Y is a single directory; A and B are path strings of files/directories.
COMMAND DESCRIPTION
Wildcard symbol for variable length, e.g., *.txt refers to all files
*
extension
ls List the names of files and subfolders in the current directory. Option
COMMAND DESCRIPTION
Also show details of each item displayed, such as user permissions and
ls -l
when the item was last modified
Change directory to Y.
cd Y Special instances of Y:
. — current directory
.. — parent directory
diff A
Compare two files A and B for differences. Outputs the difference.
B
mv A B Move a file from path A to path B. Also used for renaming files.
COMMAND DESCRIPTION
Examples:
- Moving between directories folder1 and folder2:
mv ./folder1/file.txt ./folder2
The file name will remain unchanged, and its new path will
be ./folder2/file.txt.
- Renaming a file: mv new_doc.txt expenses.txt
The new file name is expenses.txt.
rm -rf
Forcibly remove directory Y and its contents recursively
Y
open -e
Opens X in the default text editor (macOS: TextEdit)
X
COMMAND DESCRIPTION
touch X Create an empty file X or update the access and modification times of
cat -b
Also display line numbers as well.
X
head -n
Show the first 4 lines of X.
4 X
ls *.c
| head Display the first 5 items of a list of *.c files in the current direc
-n 5
Display the last 10 lines of the file(s) X specified, and track chang
tail -f
them at the end. Overwriting X or modifying X with a text editor su
X
would mess up this command’s output.
Read a file with forward and backward navigation. Often used with pipe,
less
file.txt | less
COMMAND DESCRIPTION
ln -s A
Create symbolic link of path A to link name S.
S
MEMBERSHIP →
00
DAYS
02
HRS
01
MINS
53
SECS
Input/Output Redirection
These are helpful for logging program output and error messages.
COMMAND DESCRIPTION
echo -n
Omits trailing newline of TEXT.
TEXT
cmd >
Suppress the output of cmd.
/dev/null
cmd << Read input of cmd from the standard input with the delimiter
delim character delim to tell the system where to terminate the input
COMMAND DESCRIPTION
cmd <<<
Input a text string to cmd.
string
cmd &> file Redirect output and error messages of cmd to file.
Search and Filter
COMMAND DESCRIPTION
grep -l patt X Write to standard output the names of files containing pat
find /path/to/src Find all files in /path/to/src matching the pattern "*.
-name "*.sh" file name.
COMMAND DESCRIPTION
tar -tf archive.tar List contents of the TAR archive named archive.tar.
tar -xzf
Extract the gzip-compressed TAR archive named archive
archive.tar.gz
tar -xjf
Extract the bzip2-compressed TAR archive named archiv
archive.tar.bz2
gzip -d Y.gz
Extract Y.gz and recover the original file Y.
gunzip Y.gz
bzip2 -d Y.gz
Extract Y.bz2 and recover the original file Y.
bunzip2 Y.gz
File Transfer
These commands are for logging in to local and remote hosts, and for uploading and
downloading files, transferring them between devices. Remember to omit the square
brackets "[" and "]" when you input the optional parameters they enclose.
COMMAND DESCRIPTION
Example usage:
scp alice@pi:/home/source bob@arduino:/d
scp [user1@]host1:[path1]
[user2@]host2:[path2] path1 and path2 may be local or remote, but
scp -r [user1@]host1:
Recursively copy all files and directories
[path1] [user2@]host2:
from path1 to path2.
[path2]
will be used.
MEMBERSHIP →
00
DAYS
02
HRS
01
MINS
53
SECS
File Permissions
Not all files are equally accessible. To prevent unwanted tampering, some files on your
device may be read-only. For more information about file permissions on Linux, refer to
our Linux File Permissions Cheat Sheet.
COMMAND DESCRIPTION
file
chgrp group2
Change the group of a file to group2.
file
Usage examples:
The table below compares Linux file permissions in octal form and in the
format [u/g/o/a][+/-/=][r/w/x].
0 No permissions -rwx
General
These provide information about your Linux machine and perform administrative tasks.
COMMAND DESCRIPTION
uptime Show how long the system is running and load information.
man COMMAND Shows the manual for a given COMMAND. To exit the manual, pre
cat /etc/*- Show the version of the Linux distribution installed. For exampl
release using Red Hat Linux, you may replace * with redhat.
Hardware
These commands provide details about the hardware supporting your Linux machine.
COMMAND DESCRIPTION
cat /proc/cpuinfo Display information about the central processing unit (CPU)
hdparm -i
Display information about the disk sda
/dev/sda
hdparm -tT
Perform a read speed test on the disk sda
/dev/sda
badblocks -s
Test for unreadable blocks on the disk sda
/dev/sda
Disk Usage
COMMAND DESCRIPTION
Linux Command Line Cheat Sheet Search Linux Command Line Cheat Sheet S
Networking Networking
Conclusion Conclusion
COURSES COURSES
Table of Contents Table of Contents
BLOG BLOG
RESOURCES RESOURCES
User Management
These commands give information on the system’s users and allows superuser
administrators to change user settings.
COMMAND DESCRIPTION
w Display what users are online and what they are doing
last Display the last users who have logged onto the system
usermod -aG gp1 ab1 Add the account ab1 to the group gp1
Networking
These commands regulate how your Linux machine communicates with other computers,
such as the local area network (LAN) router or external websites.
COMMAND DESCRIPTION
ifconfig -a Display all network interfaces, even if any of them is down, with
ifconfig
Display IP addresses and details of the eth0 interface
eth0
ethtool
Query or control network driver and hardware settings of the inter
eth0
netstat -
Show listening TCP and UDP ports and corresponding programs
nutlp
domain
curl LINK Display the HTML source of LINK. Check out our curl Cheat Sheet
MEMBERSHIP →
00
DAYS
02
HRS
01
MINS
53
SECS
Know your system’s Linux distribution to understand the correct installation commands
tailored to it. If the package comes with a README component, it should contain
application-specific installation instructions such as extracting TAR files (refer to this
article’s Archives section), ./setup.sh, and make install.
PACK
LINUX DISTRIBUTION PACKAGE FILE EXTENSION
INST
Here are the commands for package management in popular Linux distributions.
ROCKY / FEDORA /
ARCH LINUX / MAN
LINUX DISTRIBUTION DEBIAN / UBUNTU RED HAT ENTERPRISE
GARUDA / CHAKRA
LINUX
The command pa
Update list of packages
sudo apt dnf check- Syy achieves
available from remote
update update but may damage
repositories
Use pacman -
sudo apt
Remove / uninstall a sudo dnf erase
remove pacman -R pa
package package
package
Conclusion
Learning basic Linux commands is a great way to kickstart your education in IT and
cyber security. You’re now ready to practice them on any Linux distribution you fancy. If
you want to focus on cyber security, go for Kali Linux and Parrot OS. Also, don't forget
to check out our Unix Commands Cheat Sheet here.
Take your Linux skills to the next level with comprehensive Linux training modules
included in our StationX Membership.