Linux commands everyone should know
Last updated on July 21st, 2024If you’ve just switched to Linux, or find yourself needing to do work in Linux shell, then this list of core Linux commands along with a brief description of their functionality is for you.
Linux shell is similar to Command Prompt/PowerShell in Windows, it uses text-based commands to conduct both basic and powerful actions.
It’s a good idea to refer to the manual pages (‘man command
‘ e.g. ‘man cp
‘) for detailed information on a command you’re not familiar with to understand its usage and options.
man
: Display the manual for a command.
Example:man command
(e.g.man ls
)ls
: List files and directories in the current directory.
Example:ls
pwd
: Print the current working directory.
Example:pwd
cd
: Change directory.
Example:cd /path/to/directory
cp
: Copy files or directories. (See scp (#37) for copying files between hosts).
Example:cp file.txt destination_directory/
mv
: Move or rename files or directories.
Example:mv file.txt new_location/
ormv old_file.txt new_file.txt
rm
: Remove files or directories.
Example:rm file.txt
(Note: Be careful with this command, as it deletes files permanently. There is no undo/recycle bin)mkdir
: Create a new directory.
Example:mkdir new_directory
rmdir
: Remove an empty directory.
Example:rmdir empty_directory
touch
: Update the access and modification times of a file. This creates an empty file if the file doesn’t exist.
Example:touch new_file.txt
cat
: Display the contents of a file.
Example:cat file.txt
grep
: Search for a pattern in a file or stream of text.
Example:grep "pattern" file.txt
chmod
: Change file permissions.
Example:chmod +x script.sh
(Grants execute permission to a script.)chown
: Change file ownership.
Example:chown user:group file.txt
ps
: Display information about currently running processes.
Example:ps aux
kill
: Terminate a process.
Example:kill process_id
df
: Display information about disk space usage.
Example:df -h
du
: Estimate file space usage.
Example:du -sh directory/
zip
: Package and compress files.
Example:zip archive.zip file1.txt file2.txt
unzip
: Unzip compressed files.
Example:unzip archive.zip
tar
: Archive files.
Example:tar -cvf archive.tar.gz directory/
tar
(extract): Extract files from an archive.
Example:tar -xvf archive.tar.gz
wget
: Download files from the internet.
Example:wget https://example.com/file.txt
echo
: Display a message or a variable value.
Example:echo "Hello, World!"
nano
: A simple text file editor.
Example:nano filename
vi
orvim
: A more advanced text file editor.
Example:vim filename
head
: Display the first few lines of a file.
Example:head filename
tail
: Display the last few lines of a file. This is really useful when reading the last entries in a log file.
Example:tail filename
find
: Search for files in a directory hierarchy.
Example:find /path/to/search -name "*.txt"
locate
: Quickly find the location of files.
Example:locate filename
awk
: A powerful programming language for pattern scanning and text processing.
Example:awk '{print $1}' filename
(Prints the first column of a file.)sed
: Stream editor for filtering and transforming text.
Example:sed 's/old/new/' filename
(Replaces ‘old’ with ‘new’ in a file.)ping
: Test the reachability of a host on an Internet Protocol (IP) network.
Example:ping google.com
traceroute
: Display the route that packets take to reach a network host.
Example:traceroute google.com
ifconfig
: Display or configure network interfaces.
Example:ifconfig
netstat
: Display network connections, routing tables, interface statistics, masquerade connections, and multicast memberships.
Example:netstat -a
scp
: Securely copy files between hosts.
Example:scp file.txt user@remote:/path/to/destination/
ssh
: OpenSSH client (remote login program).
Example:ssh user@hostname
history
: Display the command history.
Example:history
psql
: Command-line interface for PostgreSQL database.
Example:psql -U username -d database_name
These are just 40 examples to get you started on the most common areas of use for shell commands. Don’t forget that each command has various options and flags that you can explore by checking their manual pages (man command
e.g. ‘man cp
‘). I strongly recommend checking the manual pages careful for destructive commands. As with PowerShell in Windows, Linux shell commands can be extremely powerful.
Best of wishes for your journey into Linux shell commands!