Linux is a powerful and diverse operating system, so naturally, the command line offers a wealth of power and functionality. If you’re starting on your journey toward Linux mastery, here are a few of the most commonly used commands that will carry you a long way.
ls: Lists all files and directories in the present working directory. You can use flags like
-lfor long listing,
-ato show hidden files, and
-hto show file size in human-readable format.
cd: Changes the current directory. You can use
cd ..to go one directory up,
cd /to go to the root directory.
pwd: Displays the present working directory. It shows the full path starting from the root directory.
touch: Creates a new file. For example,
touch newfile.txtwill create a new file named
cp: Copies files from the source directory to the destination directory. For example,
cp source.txt destination.txtwill copy
mv: Moves files between directories, or renames a file. For example,
mv oldname.txt newname.txtwill rename
rm: Deletes a directory or a file. Be careful with this command, as the deleted files cannot be recovered. Use
-rflag to remove directories.
find: Searches for files and directories. For example,
find /home -name myfile.txtwill search for
ps: Displays your currently active processes. Use
auxflags to view all running processes on the system.
top: Displays all running processes and their usage of system resources like CPU and memory.
kill: Kills a process. You need to know the PID (Process ID) of the process to kill it.
bg: Sends a process to the background. This is useful if you have a process that you want to keep running while you do other things.
fg: Brings a process to the foreground. If you have a process running in the background, you can bring it to the foreground with this command.
chmod: Changes the permissions of a file or directory. Permissions are defined as a three-digit code, where each digit is an integer between 0-7.
chown: Changes the owner and group of a file or directory. For example,
chown user:group file.txtwill change the owner of
userand the group to
chgrp: Changes the group of a file or directory. For example,
chgrp group file.txtwill change the group of
ping: Sends an ICMP echo request to establish a connection to server/IP. This is useful for troubleshooting network connectivity issues.
netstat: Displays network statistics. This is useful for checking your network connections, and for troubleshooting.
ssh: Secure Shell to get remote control of any Linux machine. For example,
ssh user@hostnamewill start a SSH session with
scp: Securely copies files between hosts on a network. For example,
scp source.txt user@hostname:/pathwill copy
apt-get: APT package handling utility (Debian). You can use
apt-get install packageto install a package,
apt-get remove packageto remove a package.
yum: Package manager (Red Hat). Similar to
apt-get, you can use
yum install packageto install a package,
yum remove packageto remove a package.
dnf: Next-generation package manager (Fedora). It’s the successor to
yumand uses the same syntax.
df: Shows disk usage. It displays the amount of disk space used and available on your filesystem.
du: Estimates file and directory space usage. For example,
du -sh /pathwill show the total disk usage of
/pathin human-readable format.
fdisk: Disk partition manipulator. It’s a powerful tool for creating, deleting, resizing, and managing disk partitions.
dd: Converts and copies a file. It’s a low-level command that allows you to make exact copies of a file, convert data formats, and more.
cat: Concatenates and displays file content. For example,
cat file.txtwill display the content of
more: Views the contents of a file one screen at a time. This is useful for viewing large files.
less: Opposite of the ‘more’ command. It allows backward navigation in the file as well as forward navigation.
head: Displays the beginning of a file. For example,
head -n 5 file.txtwill display the first 5 lines of
tail: Displays the end of a file. For example,
tail -n 5 file.txtwill display the last 5 lines of
sort: Sorts the contents of a text file. For example,
sort file.txtwill sort the lines in
cut: Removes sections from lines of files. For example,
cut -d':' -f1 /etc/passwdwill display the first field of each line in
wc: Counts lines, words, and characters in specified files. For example,
wc -l file.txtwill count the number of lines in
uname: Shows system information. For example,
uname -awill display all system information, including machine name, kernel name, version, and more.
uptime: Shows how long the system has been running. It displays the current time, how long the system has been running, how many users are currently logged on, and the system load averages for the past 1, 5, and 15 minutes.
hostname: Displays the system’s host-name. This is the name that the system is known by to other systems on the network.
useradd: Creates a new user. For example,
useradd johnwill create a new user named
userdel: Deletes a user account. For example,
userdel johnwill delete the user
johnand his home directory.
su: Switches the user ID to another user. For example,
su johnwill switch the current session’s user to
sudo: Executes commands as another user. For example,
sudo apt-get updatewill run the
apt-get updatecommand with root privileges.
passwd: Changes the user password. For example,
passwd johnwill change the password for the user
Compression / Decompression
tar: Stores and extracts files from a tape or disk archive. For example,
tar -cvf archive.tar file1 file2will create an archive named
gzip: Compresses or decompresses named files. For example,
gzip file.txtwill compress
gunzip: Decompresses files. For example,
gunzip file.txt.gzwill decompress
zip: Package and compress files. For example,
zip archive.zip file1 file2will create a compressed archive named
unzip: Extract files from a ZIP archive. For example,
unzip archive.zipwill extract all files from
grep: Searches the input files for a pattern. For example,
grep 'pattern' file.txtwill search for
locate: Finds files by name. For example,
locate file.txtwill find all instances of
file.txtin the system.
These top 50 Linux commands provide a solid foundation for efficiently navigating and managing your Linux system. Experiment with them in your terminal to gain confidence and proficiency, gradually unlocking the full potential of the command line.