Essential Linux Commands: A Beginner's Guide

New Linux converts from the Windows world may find working with the command line somewhat intimidating. However, it’s not that difficult to use. All you need to get started with the command line is to learn a few basic commands.
While most Linux distributions are user-friendly and come with an easy-to-use graphical interface, knowing the command line can be very useful. The command line gives you greater control over your system and access to features not available through a graphical interface.
In this article, we’ll look at some of the most common Linux commands that system administrators use every day.
Getting Information About the Command
Memorizing command options is usually not necessary and may be a waste of time. Usually, if you don’t use a command frequently, you can easily forget its options.
Most commands have a --help option, which prints a short message about how to use the command and exits:
command_name --helpThe man command
Almost all Linux commands come with man pages. A man page is documentation that explains what the command does, how to use it, and what arguments it accepts.
The man command displays the manual page for a given command.
man command_nameFor example, to open the man page of the cd command, you would type:
man cdTo navigate the man pages, use the Arrow, Page Up, and Page Down keys. You can also press the Enter key to move one line at a time, the Space bar to move to the next screen, and the b key to go one screen back. To exit the man page, press q.
Navigating the File System
In Linux, every file and directory is under the root directory, the first or top-most directory in the directory tree. The root directory is referred to as a single leading slash /.
When navigating the file system and operating on files, you can use either the absolute or the relative path to the resource.
An absolute path (or full path) starts from the root directory (/), while a relative path starts from your current directory.
Current Working Directory (pwd command)
The current working directory is the directory the user is currently in. Each time you interact with your command prompt, you are working within a directory.
Use the pwd command to find out what directory you are currently in:
pwdThe command displays the path of your current working directory:
/home/linuxizeChanging directory (cd command)
The cd
(“change directory”) command changes the current working directory in Linux and other Unix-like operating systems.
If you use cd without any arguments, it takes you to your home directory:
cdTo switch to a different directory, you can use either its absolute path or its relative path.
Assuming that the directory Downloads exists in the directory from which you run the command, you can navigate to it by using the relative path to the directory:
cd DownloadsYou can also navigate to a directory by using its absolute path:
cd /home/linuxize/DownloadsTwo dots (..), one after the other, represent the parent directory or, in other words, the directory immediately above the current one.
If you’re in the /usr/local/share directory and want to move up one level to /usr/local, type:
cd ../To move two levels up:
cd ../../To return back to the previous working directory, use the dash (-) character as an argument:
cd -If the directory name has spaces, you can put the path in quotes or use a backslash (\) before each space:
cd Dir\ name\ with\ spaceWorking with Files and Directories
Listing directory contents (ls command)
The ls
command shows information about files and directories within a directory.
If you run ls with no options, it lists all the files in your current directory in alphabetical order:
lsTo list files in a specific directory, pass the path to the directory as an argument:
ls /usrBy default, ls only shows the names of files and folders. Use the -l option to see more details in a long listing format:
ls -l /etc/hostsThe output includes the file type, permissions, number of hard links, owner, group, size, date, and filename:
-rw-r--r-- 1 root root 337 Oct 4 11:31 /etc/hostsBy default, ls doesn’t show hidden files. A hidden file is any file that starts with a period (.).
To see all files, including hidden ones, use the -a option:
ls -a ~/Displaying file contents (cat command)
The cat
command prints the contents of one or more files and merges (concatenates) files by appending one file’s contents to the end of another file.
To show a file’s contents on the screen, type cat followed by the file name:
cat /etc/hostsViewing file beginning and end (head and tail commands)
The head
command shows the beginning of a file. By default, it displays the first 10 lines:
head /var/log/syslogTo display a specific number of lines, use the -n option:
head -n 20 /var/log/syslogThe tail
command shows the end of a file. By default, it displays the last 10 lines:
tail /var/log/syslogUse the -f option to watch a log file update in real time:
tail -f /var/log/syslogCreating files (touch command)
The touch
command updates the timestamps of existing files and directories, and creates new, empty files.
To create a file , specify the file name as an argument:
touch file.txtIf the file already exists, touch updates its last access and modification times to the current time.
Creating directories (mkdir command)
In Linux, you can create new directories (also known as folders) with the mkdir
command.
To create a directory, type mkdir followed by the directory name:
mkdir /tmp/newdirectorymkdir can take one or more directory names as its arguments.
If the argument is a directory name, without the full path, the new directory is created in the current working directory.
To create parent directories, use the -p option:
mkdir -p Projects/linuxize.com/src/assets/imagesThis command creates the entire directory structure in a single step.
When mkdir is invoked with the -p option, it creates the directory only if it doesn’t exist.
Creating symbolic links (ln command)
A symbolic link (or symlink) is a special type of file that points to another file or directory.
To make a symbolic link to a file, use the ln
command with the -s option. The first argument is the file you want to link to, and the second is the name of the symlink:
ln -s source_file symbolic_linkIf only one file is given as an argument, ln creates a link to that file in the current working directory with the same name as the file it points to.
Removing files and directories (rm command)
Use the rm
command to delete directories and folders.
By default, when executed without any options, rm doesn’t remove directories. It also doesn’t prompt the user to confirm whether to proceed with removing the given files.
To delete a file or symlink, type rm followed by the file name:
rm file.txtrm accepts one or more file or directory names as its arguments.
The -i option tells rm to prompt the user for each given file before removing it:
rm -i file.txtrm: remove regular empty file 'file.txt'?Use the -d option to remove one or more empty directories:
rm -d dirnameTo remove non-empty directories and all the files within them recursively, use the -r (recursive) option:
rm -rf dirnameThe -f option tells rm never to prompt the user and to ignore nonexistent files and arguments.
rm -rf, because it will permanently delete files without asking you first.Copying files and directories (cp command)
The cp
command allows you to copy files and directories.
To copy a file in the current working directory, use the source file as a first argument and the new file as the second:
cp file file_backupTo copy a file to another directory, specify the absolute or the relative path to the destination directory. When only the directory name is specified as the destination, the copied file will retain the original file’s name.
cp file.txt /backupBy default, if the destination file already exists, it will be overwritten.
To copy a directory, including all its files and subdirectories, use the -R or -r option:
cp -R Pictures /opt/backupMoving and renaming files and directories (mv command)
The mv
command (short for move) is used to rename and move files and directories from one location to another.
For example, to move a file to a directory, you would run:
mv file.txt /tmpTo rename a file, you need to specify the destination file name:
mv file.txt file1.txtThe syntax for moving directories is the same as for moving files.
To move multiple files and directories at once, specify the destination directory as the last argument:
mv file.txt file1.txt /tmpSearching for Files and Text
Finding files (find command)
The find
command allows you to search for files and directories based on various criteria such as name, type, size, and modification time.
To find a file by name in the current directory and its subdirectories:
find . -name "filename.txt"To find all directories named config:
find /etc -type d -name "config"To find all files larger than 100MB:
find / -type f -size +100MTo find files modified in the last 7 days:
find /home -mtime -7Searching text in files (grep command)
The grep
command searches for patterns in files. It’s one of the most useful and popular Linux commands.
To search for a string in a file:
grep "search_term" filename.txtTo search recursively in all files within a directory:
grep -r "search_term" /path/to/directoryTo perform a case-insensitive search, use the -i option:
grep -i "search_term" filename.txtTo display line numbers with matching lines, use the -n option:
grep -n "error" /var/log/syslogTo show only the file names containing the match, use the -l option:
grep -l "TODO" *.pySystem Information
Displaying system information (uname command)
The uname
command displays information about the system.
To display all system information:
uname -aLinux ubuntu 5.4.0-42-generic #46-Ubuntu SMP Fri Jul 10 00:24:02 UTC 2020 x86_64 x86_64 x86_64 GNU/LinuxTo display only the kernel name:
uname -sTo display the kernel version:
uname -rChecking disk space (df command)
The df
(disk free) command displays the amount of available disk space on file systems.
To display disk space in a human-readable format:
df -hFilesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 45G 50G 48% /
/dev/sdb1 500G 200G 275G 43% /homeTo display information about a specific file system:
df -h /homeChecking directory size (du command)
The du
(disk usage) command estimates the space used by files and directories.
To display the size of a directory in human-readable format:
du -sh /var/logTo display the size of each subdirectory:
du -h --max-depth=1 /homeChecking memory usage (free command)
The free
command displays the amount of free and used memory in the system.
To display memory in a human-readable format:
free -h total used free shared buff/cache available
Mem: 15Gi 4.2Gi 6.8Gi 512Mi 4.5Gi 10Gi
Swap: 2.0Gi 0B 2.0GiMonitoring system processes (top and htop commands)
The top command provides a real-time view of running processes and system resource usage:
topPress q to exit the top command.
The htop command is an interactive process viewer with a more user-friendly interface:
htophtop may not be installed by default. Install it using sudo apt install htop on Debian/Ubuntu or sudo dnf install htop on Fedora/CentOS.Network Commands
Testing network connectivity (ping command)
The ping
command is used to test the reachability of a host on an IP network.
To ping a host:
ping google.comTo send a specific number of packets, use the -c option:
ping -c 5 google.comPress Ctrl+C to stop the ping command.
Downloading files (wget and curl commands)
The wget
command is used to download files from the Internet.
To download a file:
wget https://example.com/file.tar.gzTo save the file with a different name:
wget -O newname.tar.gz https://example.com/file.tar.gzThe curl
command is a versatile tool for transferring data from or to a server.
To download a file and save it:
curl -O https://example.com/file.tar.gzTo display the contents of a URL:
curl https://example.comDisplaying network configuration (ip command)
The ip
command is used to show and manipulate network interfaces, routing, and tunnels.
To display all network interfaces:
ip addr showTo display the routing table:
ip route showWorking with Archives
Creating and extracting archives (tar command)
The tar
command creates and extracts archive files.
To create a tar archive:
tar -cvf archive.tar /path/to/directoryTo create a compressed tar.gz archive:
tar -czvf archive.tar.gz /path/to/directoryTo extract a tar archive:
tar -xvf archive.tarTo extract a tar.gz archive:
tar -xzvf archive.tar.gzTo extract to a specific directory:
tar -xzvf archive.tar.gz -C /path/to/destinationWorking with zip archives (zip and unzip commands)
The zip
command creates compressed zip archives:
zip archive.zip file1.txt file2.txtTo zip a directory recursively:
zip -r archive.zip /path/to/directoryThe unzip
command extracts zip archives:
unzip archive.zipTo extract to a specific directory:
unzip archive.zip -d /path/to/destinationInstalling and Removing Packages
A package manager is a tool that allows you to install, update, remove, and otherwise manage distro-specific software packages.
Different Linux distributions have different package managers and package formats.
Only root or a user with sudo privileges can install and remove packages.
Ubuntu and Debian (apt command)
Advanced Package Tool, or APT, is a package management system used by Debian-based distributions.
There are several command-line package management tools in Debian distributions, with apt
and apt-get being the most used ones.
Before installing a new package, first you need to update the APT package index:
apt updateThe APT index is a database that holds records of available packages from the repositories enabled in your system.
To upgrade all installed packages to their latest versions, run:
apt upgradeInstalling packages is as simple as running:
apt install package_nameTo remove an installed package , enter:
apt remove package_nameCentOS and Fedora (dnf command)
RPM is a powerful package management system used by Red Hat Linux and its derivatives, such as CentOS and Fedora. RPM also refers to the rpm
command and the .rpm file format.
To install a new package
on Red Hat based distributions, you can use either the yum or dnf commands:
dnf install package_nameStarting from CentOS 8, dnf replaced yum as the default package manager. dnf is backward compatible with yum.
To upgrade all installed packages to their latest versions, type:
dnf updateRemoving packages is as simple as:
dnf remove package_nameFile Ownership and Permissions
In Linux, access to the files is managed through file permissions, attributes, and ownership. This ensures that only authorized users and processes can access files and directories.
In Linux, each file is associated with an owner and a group and assigned permission access rights for three different classes of users:
- The file owner.
- The group members.
- Everybody else.
Three permission types apply to each class:
- The read permission.
- The write permission.
- The execute permission.
This concept allows you to specify which users can read, write, or execute the file.
To view the file owner and permissions, use the ls -l command.
Changing permissions (chmod command)
The chmod
command allows you to change the file permissions. It works in two modes, symbolic and numeric.
In numeric mode, you can set permissions for the owner, the group, and all others. Each write, read, and execute permissions have the following number value:
r(read) = 4w(write) = 2x(execute) = 1- no permissions = 0
The permission number of a specific user class is represented by the sum of the values of the permissions for that group.
For example, to give the file’s owner read and write permissions and only read permissions to group members and all other users, you would run:
chmod 644 filenameOnly the root user, the file owner, or someone with sudo privileges can change file permissions.
To recursively
operate on all files and directories under a given directory, use the chmod command with the -R, (–recursive) option:
chmod -R 755 dirnameBe extra careful when recursively changing the files’ permissions.
Changing ownership (chown command)
The chown
command lets you change the user and group ownership of a given file, directory, or symbolic link.
To change a file’s owner, type chown, the new owner’s username, and the file name:
chown username filenameTo change both the owner and the group of a file, invoke the chown command followed by the new owner and group separated by a colon (:) with no intervening spaces and the target file:
chown username:groupname filenameUse the -R (--recursive) option, to recursively operate on all files and directories under the given directory:
chown -R username:groupname dirnameElevate privileges (sudo command)
The sudo
command allows you to run programs as another user, by default, the root user. If you spend a lot of time on the command line, sudo is one of the commands you will use quite frequently.
Using sudo instead of logging in as root is more secure because you can grant limited administrative privileges to individual users without them knowing the root password.
To use sudo, just put sudo before your command:
sudo commandManaging Users and Groups
Linux is a multi-user system, meaning more than one person can interact with the same system at the same time. Groups are used to organize and administer user accounts. The primary purpose of groups is to define a set of privileges, such as read, write, or execute permissions, for a given resource shared among the users in the group.
Creating users (useradd and passwd Commands)
The useradd
command allows you to create new users.
To create a new user account, type useradd followed by the username:
useradd newuserOnce the user is created, set the user password with the passwd
command:
passwd newuserRemoving users (userdel Command)
In Linux, you can remove a user account with the userdel
command.
To delete a user account, pass the user name to the userdel command:
userdel newuserUse the -r (–remove) option to delete the user’s home directory and mail spool:
userdel -r newuserManaging groups (groupadd and groupdel Command)
To create a new group, invoke the groupadd
command followed by the group name:
groupadd mygroupTo remove a group, use the groupdel
command with the group name as an argument:
groupdel mygroupAdding users to groups (usermod Command)
To add an existing user to a group, use the usermod
command followed by the -G option and the name of the group:
usermod -a -G sudo linuxizeQuick Reference
Here’s a summary of all the commands we covered in this article:
| Command | Description |
|---|---|
man | Display manual page for a command |
pwd | Print current working directory |
cd | Change directory |
ls | List directory contents |
cat | Display file contents |
head | Display first lines of a file |
tail | Display last lines of a file |
touch | Create empty file or update timestamps |
mkdir | Create directories |
ln | Create symbolic links |
rm | Remove files and directories |
cp | Copy files and directories |
mv | Move or rename files and directories |
find | Search for files |
grep | Search text in files |
uname | Display system information |
df | Display disk space usage |
du | Display directory size |
free | Display memory usage |
top | Display running processes |
ping | Test network connectivity |
wget | Download files from the web |
curl | Transfer data from/to servers |
ip | Display network configuration |
tar | Create and extract archives |
zip | Create zip archives |
unzip | Extract zip archives |
apt | Package manager for Debian/Ubuntu |
dnf | Package manager for Fedora/CentOS |
chmod | Change file permissions |
chown | Change file ownership |
sudo | Execute command as root |
useradd | Create new user |
userdel | Delete user |
passwd | Change user password |
groupadd | Create new group |
groupdel | Delete group |
usermod | Modify user account |
Conclusion
We have covered some of the most used GNU/Linux commands for file management, text searching, system information, networking, archiving, package management, and user administration.
Although you can perform most of the development and system-related tasks using a graphical interface, the command line makes you more productive and able to get more done in less time.
Click the links for each command to learn more about their options and how to use them.
If you have any questions or feedback, feel free to leave a comment.
Tags
Linuxize Weekly Newsletter
A quick weekly roundup of new tutorials, news, and tips.
About the authors

Dejan Panovski
Dejan Panovski is the founder of Linuxize, an RHCSA-certified Linux system administrator and DevOps engineer based in Skopje, Macedonia. Author of 800+ Linux tutorials with 20+ years of experience turning complex Linux tasks into clear, reliable guides.
View author page