DEV Community

Cover image for Top 33 Ubuntu Linux Commands with Outputs - Every User Should Know
Ömer Berat Sezer
Ömer Berat Sezer

Posted on

Top 33 Ubuntu Linux Commands with Outputs - Every User Should Know

Motivation: Why should learn?

  • Linux is important due to its widespread use in servers, cloud computing, and DevOps, making it a cornerstone of modern IT infrastructure.
  • Learning commands is essential because it enables efficient interaction with operating systems, automates repetitive tasks, and improves productivity.
  • Mastering commands provides greater control over system operations, troubleshooting, and scripting.

Important commands are listed as follows:

ls

  • It lists files and directories in the current directory
user@ubuntu:~ $ ls                        
# list 
user@ubuntu:~ $ ls -l                    
# long listing with permissions 
drwxr-xr-x  6 user user     4096 Nov 1 12:42    .cache
-rw-r--r--  1 user user     12   Nov 1 11:54     abc.txt
user@ubuntu:~ $ ls -a                   
# include hidden files
.docker  .gitconfig .cache             
# . shows hidden files
Enter fullscreen mode Exit fullscreen mode

cd

  • It changes directory
user@ubuntu:~ $ cd /home/user/ubuntu 
user@ubuntu:~/ubuntu $ cd ..                       
# go up one directory level

Enter fullscreen mode Exit fullscreen mode

pwd

  • It shows current directory path
user@ubuntu:~ $ pwd
/home/user
Enter fullscreen mode Exit fullscreen mode

mkdir

  • It creates a new directory.
user@ubuntu:~ $ mkdir directory_name
user@ubuntu:~ $ mkdir test
test
Enter fullscreen mode Exit fullscreen mode

rm

  • It removes files or directories.
user@ubuntu:~ $ rm file_name  
# remove file
user@ubuntu:~ $ rm -r directory 
# remove directory and contents recursively
Enter fullscreen mode Exit fullscreen mode

cp

  • It copies files and directories
user@ubuntu:~ $ cp source_file  destination 
user@ubuntu:~ $ cp -r source_dir destination_dir       
# copy directories, subdirectories and files recursively (-r)
Enter fullscreen mode Exit fullscreen mode

mv

  • It moves or rename files and directories
user@ubuntu:~ $ mv old_name new_name 
user@ubuntu:~ $ mv file /new/path
Enter fullscreen mode Exit fullscreen mode

sudo

  • It allows a permitted user to execute a command as the superuser (root)
user@ubuntu:~ $ sudo command
user@ubuntu:~ $ sudo apt update
user@ubuntu:~ $ sudo apt install package_name
Enter fullscreen mode Exit fullscreen mode

touch

  • It creates an empty file or update file's timestamp
user@ubuntu:~ $ touch file_name
user@ubuntu:~ $ touch abc.txt
Enter fullscreen mode Exit fullscreen mode

cat

  • It views the contents of a file
user@ubuntu:~ $ cat file_name
user@ubuntu:~ $ cat abc.txt
acb123
Enter fullscreen mode Exit fullscreen mode

nano, vim

  • Command-line text editors
user@ubuntu:~ $ nano file_name 
user@ubuntu:~ $ vim file_name
Enter fullscreen mode Exit fullscreen mode

ps

  • It displays currently running processes.
user@ubuntu:~ $ ps aux
USER    PID  %CPU  %MEM    VSZ    RSS   TTY    STAT  START   TIME  COMMAND
user      9   0.0   0.0   10572  5540   pts/0    S   18:32   0:00   -bash
root     74   0.0   0.0   11020  4556   pts/0    S   18:32   0:00  dockerd
Enter fullscreen mode Exit fullscreen mode

top, htop

  • Interactive process viewer.
user@ubuntu:~ $ top
top - 19:18:48 up 46 min,  0 users,  load average: 0.00, 0.00, 0.00
Tasks:   8 total,   1 running,   7 sleeping,   0 stopped,   0 zombie
%Cpu(s):  0.0 us,  0.0 sy,  0.0 ni,100.0 id,  0.0 wa,  0.0 hi,  0.0 si,  0.0 st
MiB Mem :  12522.4 total,  11690.3 free,    185.2 used,    646.9 buff/cache
MiB Swap:   4096.0 total,   4096.0 free,      0.0 used.  12088.1 avail Mem

PIDUSER PR   NI VIRT RES   SHR   S      %CPU  %MEM   TIME+     COMMAND
  75   root  20   0  1845  1122  54884  0.7    0.9   0:21.04   dockerd
Enter fullscreen mode Exit fullscreen mode

kill

  • It terminates a process by PID.
user@ubuntu:~ $ kill PID_number
user@ubuntu:~$ sleep 100 &                           
# sleep 100 sec background
[1] 1425
user@ubuntu:~$ ps
  PID TTY          TIME CMD
 1425 pts/0    00:00:00 sleep
user@ubuntu:~$ kill 1425
user@ubuntu:~$ kill -9 1425                       
# -9 force to terminate process

Enter fullscreen mode Exit fullscreen mode

pkill

  • It terminates processes by name.
user@ubuntu:~ $ pkill process_name
user@ubuntu:~ $ sleep 100 &
[1] 1402
user@ubuntu:~ $ pkill sleep
[1]+  Terminated   sleep 100
Enter fullscreen mode Exit fullscreen mode

df

  • It shows disk usage of file systems.
user@ubuntu:~ $ df -h                                            
# human-readable format
user@ubuntu:~ $ df -ah    
Filesystem      Size   Used     Avail       Use%     Mounted on
/dev/sdb        251G    23G      216G       10%        /
tmpfs           6.2G     0       6.2G        0%        /mnt/a
Enter fullscreen mode Exit fullscreen mode

free

  • It displays memory usage.
user@ubuntu:~ $ free -h                                       
# human-readable format
          total     used     free      shared   buff/cache    available
Mem:       12Gi     164Mi    11Gi       0.0Ki       646Mi          11Gi
Swap:      4.0Gi     0B      4.0Gi
Enter fullscreen mode Exit fullscreen mode

ifconfig

  • It displays or configures network interfaces and IP.
user@ubuntu:~ $ ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.7  netmask 255.255.240.0  broadcast 192.168.255.255
        inet6 ab80::215:5cdd:efc2:8a3b  prefixlen 64  scopeid 0x20<link>
        ether 00:23:a3:b1:cd:ef  txqueuelen 1000  (Ethernet)
        RX packets 528  bytes 48315 (48.3 KB)
        RX errors 0  dropped 2  overruns 0  frame 0
        TX packets 25  bytes 1838 (1.8 KB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
Enter fullscreen mode Exit fullscreen mode

ping

  • It tests connectivity to a network host.
user@ubuntu:~ $ ping example.com
user@ubuntu:~ $ ping 192.168.2.5
PING 192.168.2.5 (192.168.2.5) 56(84) bytes of data.
64 bytes from 192.168.2.5: icmp_seq=1 ttl=61 time=18.5 ms
^C
--- 192.168.2.5 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1002ms
rtt min/avg/max/mdev = 18.461/19.088/19.716/0.627 ms
Enter fullscreen mode Exit fullscreen mode

netstat

  • It displays network connections, routing tables, and more.
user@ubuntu:~ $ netstat -tuln           
# -t => tcp, -u => udp, -l => listening
Active Internet connections (only servers)
Proto  Recv-Q  Send-Q  Local Address   Foreign Address     State
tcp      0       0     0.0.0.0:443      0.0.0.0:*          LISTEN
Enter fullscreen mode Exit fullscreen mode

wget

  • It downloads files from the internet.
user@ubuntu:~ $ wget http://example.com/file.zip
Enter fullscreen mode Exit fullscreen mode

curl

  • It tests and fetches information from URLs, APIs, and web pages.
user@ubuntu:~ $ curl http://ubuntu.com
user@ubuntu:~ $ curl -X POST -H "Content-Type: application/json" -d '{"name": "user", "age": 30}' http://example.com/api
# -X POST: Specifies the request type as POST.
# -H: Sets the request header, here specifying JSON content.
# -d: Sends data with the request.
user@ubuntu:~ $ curl -u username:password -O http://example.com/protectedfile.zip
Enter fullscreen mode Exit fullscreen mode

chmod

  • It changes file permissions.
user@ubuntu:~ $ chmod 755 file_name    
# read, write, execute for owner; read, execute for others
# rwx => binary 111 = decimal 7
# owner, group, others 
# - rwxrwxrwx  => 777
Enter fullscreen mode Exit fullscreen mode

chown

  • It changes file owner and group.
user@ubuntu:~ $ chown user:group file_name
user@ubuntu:~ $ chown user2:developers example.txt
# user2: the new owner (user) of the file.
# developers: the new group associated with the file.
# example.txt: the name of the file whose ownership is being changed
Enter fullscreen mode Exit fullscreen mode

tar

  • Archive files (create, extract .tar, .tar.gz files)
user@ubuntu:~ $ tar -cvf archive.tar file_or_directory 
# create archive 
user@ubuntu:~ $ tar -xvf archive.tar 
# extract archive 
user@ubuntu:~ $ tar -czvf archive.tar.gz file_or_dir 
# create compressed archive
Enter fullscreen mode Exit fullscreen mode

grep

  • It searches text within files.
user@ubuntu:~ $ grep "search_term" file_name
user@ubuntu:~ $ find /path/to/search | grep "pattern"      # with pipe | 
# pipe | => cmd1 | cmd2 => sends cmd1's output directly into cmd2
Enter fullscreen mode Exit fullscreen mode

find

  • It finds files and directories based on conditions.
user@ubuntu:~ $ find /path -name "file_name"
user@ubuntu:~ $ find /  -name "history.txt"              # type file by default
/home/user/history.txt
find: ‘/home/user/dockertest/volumedata’: Permission denied
user@ubuntu:~ $  find / -type d -name "docker"           # type d=directory
/etc/docker
Enter fullscreen mode Exit fullscreen mode

adduser

  • It creates a new user.
user@ubuntu:~ $ adduser newuser1
user@ubuntu:~ $ usermod -aG sudo newuser1    
# add the user to the sudo group

# with adduser command, the home folder for the user will be created as default
# with useradd command, there is no home folder for the user
Enter fullscreen mode Exit fullscreen mode

passwd

  • It sets or changes user password.
user@ubuntu:~ $ passwd user            
# user => username
Changing password for user.
Current password:
New password:
Retype new password:
Password changed
Enter fullscreen mode Exit fullscreen mode

apt

  • It installs, removes, or manages packages Debian-based systems (like Ubuntu)
user@ubuntu:~ $ apt update                   
# update package list
user@ubuntu:~ $ apt install package_name     
# install a package
user@ubuntu:~ $ apt remove package_name     
 # remove a package
Enter fullscreen mode Exit fullscreen mode

yum

  • It installs, removes, or manages packages RedHat-based systems (like CentOS)
[user@localhost ~]:#  yum install package_name    
# install a package
[user@localhost ~]:# yum remove package_name     
 # remove a package
Enter fullscreen mode Exit fullscreen mode

Conclusion

Linux CLI commands are significant for all IT guys: developers, devops, ops, security, cloud developers. Mastering commands provides greater control over system operations, troubleshooting, and scripting.

If you found the tutorial interesting, I’d love to hear your thoughts in the blog post comments. Feel free to share your reactions or leave a comment. I truly value your input and engagement 😉

For other posts 👉 https://dev.to/omerberatsezer 🧐

Follow for Tips, Tutorials, Hands-On Labs for AWS, Kubernetes, Docker, Linux, DevOps, Ansible, Machine Learning, Generative AI, SAAS.

https://github.com/omerbsezer/
https://www.linkedin.com/in/omerberatsezer/

Top comments (0)