Top 20 Linux Commands For Cloud and DevOps Engineers

Want to work with cloud systems and servers? Then you'll want to get comfortable with Linux. Linux is everywhere, and becoming familiar with it will really help you out. Want to set up containers, manage virtual machines, or troubleshoot servers? You'll find that Linux commands are your go-to tools for all these tasks. Knowing the right commands helps you quickly troubleshoot issues and automate tasks.
This article covers 20 Linux commands that every cloud engineer should know, with examples for each.
#Linux Commands for Cloud and DevOps Engineers
These commands will help you navigate servers, manage files, monitor performance, and automate tasks in the cloud.
Linux Dedicated Servers with Full Control
Optimize your workloads with customizable Linux bare metal servers, offering high-performance processors, reliable storage, and full root access.
#Basic navigation commands
With these commands, you can navigate the Linux filesystem. You can go from one folder to another, explore the contents of your current directory, or view your current location.
#1. ls
- List directory contents
The ls
command is one of the most commonly used Linux commands. It is used to list the contents of a directory. Running the command by itself without any arguments returns the files and directories in your current directory, except for hidden files.
Syntax:
ls [options] [directory]
Common options:
-
-l
: Shows a long listing format with detailed information like permissions, owner, size, and modification date. -
-h
: Displays file sizes in a human-readable format (like KB, MB, GB) when used with-l
. -
-a
: Lists all files and directories, including hidden ones that start with a dot (.). -
-r
: Reverses the order of the sort, such as listing files from oldest to newest instead of the default. -
-t
: Sorts the files and directories by their last modification time, showing the newest ones first. -
-R
: Recursively lists the contents of all subdirectories. -
-d
: List the directory entry itself, not the contents within it. -
-S
: Sorts the files by their size, from largest to smallest. -
-1
: Lists each file or directory on its own line.
Example:
To display a detailed, human-readable list of everything inside a projects
folder located in the current directory.
ls -lah projects
total 28K
drwxrwxr-x 7 ubuntu ubuntu 4.0K Jul 2 19:08 .
drwxr-x--- 10 ubuntu ubuntu 4.0K Jul 2 22:57 ..
drwxrwxr-x 2 ubuntu ubuntu 4.0K Jul 2 19:08 bin
drwxrwxr-x 2 ubuntu ubuntu 4.0K Jul 2 19:08 config
drwxrwxr-x 2 ubuntu ubuntu 4.0K Jul 2 19:08 logs
drwxrwxr-x 2 ubuntu ubuntu 4.0K Jul 2 19:08 scripts
drwxrwxr-x 2 ubuntu ubuntu 4.0K Jul 2 19:08 src
#2. cd
- Change directory
The cd
command allows you to move between directories. It's like clicking through folders in a file explorer.
Syntax:
cd [path to directory]
Common options:
-
cd ..
: Moves you to the parent directory (one level up) of your current location. -
cd ~
: Takes you to your home directory from anywhere in the system. -
cd -
: Switches you to the previous directory you were in. -
cd /
: Navigates to the root directory, which is the top-most level of the entire file system.
Example:
To navigate to the project
directory, then return to the home directory using ~
:
cd project
cd ~
ubuntu@ubuntu:~$ cd project
ubuntu@ubuntu:~/project$ cd ~
ubuntu@ubuntu:~$
#3. pwd
- Print working directory
The pwd
command tells you exactly where you're in the file system. It displays the full path to the current directory that you’re in. You'll need this in scripts to get a reliable path.
Syntax:
pwd
Common options:
-L
: Shows your current directory's logical path, including any symbolic links you used to get there. This is the default behavior of the pwd
command.
-P
: Displays the physical path, resolving all symbolic links to show the true, actual location on the disk.
Example:
To display the full path to the current directory and confirm that you're in the home folder:
pwd
ubuntu@ubuntu:~$ pwd
/home/ubuntu
#File and directory management
These commands are your tools for creating, copying, moving, and deleting files and directories in the Linux terminal.
#4. touch
- Create new files
The touch
command lets you create a new, empty file instantly. It can also be used to update the modification timestamp of an existing file.
touch [file_name]
Common options:
-
-a
: Updates the access time only. -
-m
: Updates the modification time only. -
-t
: Sets the file's time to a specific date and time you provide. -
-c
: Preventstouch
from creating a new file if it doesn't already exist.
Example:
Creates a new, empty file named README.md
in your current directory if it doesn't already exist, or updates its last modified timestamp if it does.
touch README.md
ubuntu@ubuntu:~$ touch README.md
ubuntu@ubuntu:~$ ls -l
total 51236
-rw-rw-r-- 1 ubuntu ubuntu 0 Jul 2 23:59 README.md
-rw-rw-r-- 1 ubuntu ubuntu 52428800 Jul 2 22:57 backup.tar.gz
drwxrwxr-x 2 ubuntu ubuntu 4096 Jul 2 22:56 backups
drwxrwxr-x 2 ubuntu ubuntu 4096 Jul 2 22:56 bin
-rw-rw-r-- 1 ubuntu ubuntu 15 Jul 2 22:57 docker-compose.yml
drwxrwxr-x 2 ubuntu ubuntu 4096 Jul 2 22:56 downloads
drwxrwxr-x 2 ubuntu ubuntu 4096 Jul 2 22:56 logs
-rw-rw-r-- 1 ubuntu ubuntu 38 Jul 2 22:57 notes.txt
drwxrwxr-x 7 ubuntu ubuntu 4096 Jul 2 19:08 project
drwxrwxr-x 2 ubuntu ubuntu 4096 Jul 2 22:56 projects
drwxrwxr-x 2 ubuntu ubuntu 4096 Jul 2 22:56 scripts
ubuntu@ubuntu:~$ touch README.md
ubuntu@ubuntu:~$ ls -l README.md
-rw-rw-r-- 1 ubuntu ubuntu 0 Jul 3 00:01 README.md
#5. mkdir
- Make directories
The mkdir
command is used to create one or more directories for managing your files and keeping your system organized.
Syntax:
mkdir [options] [directory_name]
Common options:
-
-p
: Create parent directories if they don’t already exist. -
-m
: Set permissions on the new directory when creating it. -
-v
: Prints a message in the terminal for each directory created.
Example:
To create a demo
directory along with the nested logs
and archive
subdirectories in one command:
mkdir -p demo/logs/archive
If any of the parent directories already exist, it skips them without error.
ubuntu@ubuntu:~$ mkdir -p demo/logs/archive
ubuntu@ubuntu:~$ tree demo
demo
└── logs
└── archive
3 directories, 0 files
NOTE:
If the tree
command-line utility is not installed, you will run into an error informing you that you need to install it. To do so, run the following commands:
On Ubuntu/Debian
Run the command:
sudo apt install tree
On RHEL/Fedora/Rocky/AlmaLinux
You need to enable the EPEL repository on your system first. Then run:
sudo dnf install tree
ArchLinux
Run the command:
sudo pacman -S tree
#6. cp
- Copy files and directories
You'll often need to duplicate files, maybe for backups or staging. The cp
command can help you do this. It copies files or folders from one location to another on your system.
Syntax:
cp [options] [source] [destination]
To copy an entire directory, you need to use the -r
(recursive) flag.
cp -r [options] [destination]
Common options:
-
-r
: Copy directories and their contents recursively. -
-v
: Shows files as they are being copied. -
-p
: Preserves the file attributes like mode, ownership, and timestamps. -
-i
: Prompt before overwriting an existing file. -
-u
: Copies only when the source file is newer than the destination file, or when the destination file is missing.
Example:
To copy the notes.txt
file from your current directory into the demo
folder with a new name, notes_backup.txt
:
cp notes.txt demo/notes_backup.txt
ubuntu@ubuntu:~$ cp notes.txt demo/notes_backup.txt
ubuntu@ubuntu:~$ ls demo
logs notes_backup.txt
ubuntu@ubuntu:~$
#7. mv
- Move or rename files and directories
The mv
command can either move a file or folder to a new location or rename it.
Syntax:
mv [options] [source] [destination]
When renaming, the source and the destination must be on the same path. Otherwise, when a different destination path is specified, the file will be both renamed and moved to the specified path.
mv [old_name] [new_name]
Common options:
-
-v
: Show the name of each file as it’s -
being moved.
-
-n:
Prevent overwriting. -
-i
: Prompt before overwriting an existing file. -
-u
: Move the source file if it is newer than the destination file or if the destination file is missing.
Example:
To rename notes.txt
to tasks.txt
:
mv notes.txt tasks.txt
ubuntu@ubuntu:~$ mv notes.txt tasks.txt
ubuntu@ubuntu:~$ ls
README.md backups demo downloads project scripts
backup.tar.gz bin docker-compose.yml logs projects tasks.txt
To move the file tasks.txt
into the demo
directory and rename it to tasks-archived.txt
:
mv tasks.txt demo/tasks-archived.txt
ubuntu@ubuntu:~$ mv tasks.txt demo/tasks-archived.txt
ubuntu@ubuntu:~$ ls demo
logs notes_backup.txt tasks-archived.txt
#8. rm
- Remove files and directories
The rm
command deletes files and directories permanently. This can be used for cleaning up old log files, temporary data, or failed deployment artifacts.
Syntax:
rm [options] [file_or_directory]
Common options:
-
-r
: Remove directories and their contents recursively. -
-f
: Remove files without prompting for confirmation. -
-i
: Prompt for confirmation before removing each file. -
-v
: Shows the name of each file as it’s being removed.
Example:
To delete the README.md
file in the current directory:
rm README.md
ubuntu@ubuntu:~$ rm README.md
ubuntu@ubuntu:~$ ls
backup.tar.gz bin docker-compose.yml logs projects
backups demo downloads project scripts
#Viewing and searching files
As a cloud engineer, you'll spend much time reading logs and configuration files. These commands help you view and search through text data efficiently.
#9. cat
- Concatenate and display file content
The cat
command reads a file and prints its content to the terminal. It's great for quickly viewing the entire content of a small file directly in your terminal.
Syntax:
cat [options] [file_name]
Common options:
-
-n
: Numbers all output lines, including blank ones. -
-b
: Numbers all non-blank output lines.
Example:
To display the contents of the docker-compose.yml
file in your terminal:
cat docker-compose.yml
ubuntu@ubuntu:~$ cat docker-compose.yml
version: '3.8'
#10. grep
- Search text
grep
(global regular expression print) is your tool for finding specific text or patterns within files or even the output of other commands. It is great for searching large files or across many files at once.
Syntax:
grep [options] "[pattern]" [file_name]
Common options:
-
-i
: Makes the search case-insensitive, matching both uppercase and lowercase letters. -
-n:
Displays the line number in the file for each matching line. -
-r
: Searches recursively for the pattern in all files under the given directory and its subdirectories. -
-v
: Inverts the search to show only the lines that do not contain the pattern. -
-c
: Counts the total number of matching lines instead of displaying the lines themselves.
Example:
To find all lines containing the word "ERROR" in a log file:
grep 'ERROR' project/logs/error.log
ubuntu@ubuntu:~$ grep 'ERROR' project/logs/error.log
ERROR: Database not responding
#Networking and system monitoring
This includes commands for accessing, monitoring, and maintaining servers. These Linux networks commands help you connect to remote systems, transfer files, check resource usage, and troubleshoot connectivity issues.
#11. ps
- Process status
ps
(process status) is your command to get a quick snapshot of all the processes running on your system. It is perfect for finding a specific Process ID (PID) of an application or seeing exactly what processes a particular user is running.
Syntax:
ps [options]
Common options:
-
-e
: Displays every single process running on the system. -
-f
: Shows a full-format listing with extra details like parent process ID and start time. -
-u
: Displays processes owned by a specified user. -
-a
: Shows processes for all users, including those not associated with a terminal. -
-x
: Displays processes that are not attached to any terminal, like system daemons.
Example:
To display a snapshot of all running processes on the system, including their user, CPU, and memory usage, and command:
ps aux
ubuntu@ubuntu:~$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 1.3 22496 13696 ? Ss Jul02 0:05 /usr/lib/systemd/systemd --sy
root 2 0.0 0.0 0 0 ? S Jul02 0:00 [kthreadd]
...
root 866 0.0 0.2 6148 2176 ttyS0 Ss+ Jul02 0:00 /sbin/agetty -o -p -- \u --ke
...
ubuntu 5948 0.0 1.0 14960 10400 ? Ss 05:39 0:00 sshd: ubuntu [priv]
ubuntu 6063 0.0 0.7 15540 7620 ? S 05:39 0:00 sshd: ubuntu@pts/0
ubuntu 6064 0.0 0.5 9060 5376 pts/0 Ss+ 05:39 0:00 -bash
...
ubuntu 12565 0.0 0.4 11320 4352 pts/2 R+ 06:39 0:00 ps aux
#12. top
- Monitor system processes
top
is your real-time dashboard for everything happening on your system. It gives you a dynamic, constantly updated view of all your running processes. This command is invaluable for quickly seeing what's using up your CPU, memory, and just generally keeping an eye on your server's health.
Syntax:
top [options]
Common options:
-
-u
: Shows only the processes owned by a specific user. -
-n
: Specifies the number of iterations or updatestop
will perform before exiting. -
-b
: Runstop
in batch mode, sending output to standard output without interactive commands. -
-d
: Sets the delay or interval between screen updates. -
-p
: Monitors only processes with specific process IDs (PIDs).
Example:
Run the command to get a live view of your system:
top
top - 06:43:31 up 14:59, 2 users, load average: 0.00, 0.00, 0.00
Tasks: 95 total, 1 running, 94 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 : 961.6 total, 348.7 free, 316.7 used, 476.8 buff/cache
MiB Swap: 0.0 total, 0.0 free, 0.0 used. 644.9 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
1 root 20 0 22496 13696 9600 S 0.0 1.4 0:05.88 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.01 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pool_workqueue_release
4 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/R-rcu_g
5 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/R-rcu_p
6 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/R-slub_
7 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/R-netns
9 root 0 -20 0 0 0 I 0.0 0.0 0:00.58 kworker/0:0H-kblockd
12 root 0 -20 0 0 0 I 0.0 0.0 0:00.00 kworker/R-mm_pe
13 root 20 0 0 0 0 I 0.0 0.0 0:00.00 rcu_tasks_kthread
14 root 20 0 0 0 0 I 0.0 0.0 0:00.00 rcu_tasks_rude_kthread
15 root 20 0 0 0 0 I 0.0 0.0 0:00.00 rcu_tasks_trace_kthread
16 root 20 0 0 0 0 S 0.0 0.0 0:00.63 ksoftirqd/0
17 root 20 0 0 0 0 I 0.0 0.0 0:00.84 rcu_preempt
18 root rt 0 0 0 0 S 0.0 0.0 0:00.23 migration/0
19 root -51 0 0 0 0 S 0.0 0.0 0:00.00 idle_inject/0
Press q
to exit top
. Use h
for help or M
to sort by memory usage while it’s running.
#13. df
- Display disk space usage
Running out of disk space is a common problem. The df
command displays the available and used space on your mounted file systems.
Syntax:
df [options]
Common options:
-
-h
: Displays disk space in a human-readable format (like KB, MB, GB). -
-T
: Shows the file system type for each disk (e.g., ext4, xfs, nfs). -
-a
: Includes all file systems in the listing, even pseudo and duplicate ones. -
-P
: Uses the POSIX standard output format, ensuring each entry is on a single line. -
-i
: Displays information about inodes (the data structures that store file information) instead of disk blocks.
Example:
To get a human-readable report of disk usage for all mounted filesystems, including their type:
df -Th
Filesystem Type Size Used Avail Use% Mounted on
tmpfs tmpfs 97M 1.1M 96M 2% /run
/dev/vda1 ext4 19G 2.2G 17G 12% /
tmpfs tmpfs 481M 0 481M 0% /dev/shm
tmpfs tmpfs 5.0M 0 5.0M 0% /run/lock
/dev/vda16 ext4 881M 112M 708M 14% /boot
/dev/vda15 vfat 105M 6.2M 99M 6% /boot/efi
tmpfs tmpfs 97M 12K 97M 1% /run/user/1000
#14. du
- Estimate file and directory space usage
While df
shows disk space for the whole filesystem, du
shows how much space a specific file or directory is using.
Syntax:
du [options] [path]
Common options:
-
-h
: Displays disk usage sizes in a human-readable format (like 1K, 234M, 2G). -
-a
: Shows the disk usage of all files, not just directories. -
-s
: Displays only a total summary for each item you specify. -
-c
: Appends a grand total of disk usage at the very end of the output. -
--max-depth=N
: Limits how deep du will go when showing subdirectories, up to a specified levelN
.
Example:
To display the total disk space used by the logs
directory in a human-readable format:
du -sh logs
ubuntu@ubuntu:~$ du -sh logs
4.0K logs
#15. ssh
- Secure shell
ssh
is a command-line utility for securely connecting to your remote cloud servers by leveraging the SSH protocol which listens to port 22 by default.
Syntax:
ssh [OPTIONS] username@server-ip
Common options:
-
-i
: Specifies the path to the private key file for authentication. -
-p
: Specifies the port number to connect to on the remote server(default is 22). -
-v
: Enables verbose mode, showing detailed debugging output during the connection process.
Example:
To establish a secure shell (SSH) connection to a remote server using the specified username and IP address:
ssh ubuntu@5.199.173.52
C:\Users\goodn>ssh ubuntu@5.199.173.52
ubuntu@5.199.173.52's password:
Welcome to Ubuntu 24.04.2 LTS (GNU/Linux 6.8.0-60-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/pro
System information as of Thu Jul 3 07:19:44 EEST 2025
System load: 0.0 Processes: 101
Usage of /: 11.9% of 18.33GB Users logged in: 1
Memory usage: 27% IPv4 address for eth0: 5.199.173.52
Swap usage: 0%
* Strictly confined Kubernetes makes edge and IoT secure. Learn how MicroK8s
just raised the bar for easy, resilient and secure K8s cluster deployment.
https://ubuntu.com/engage/secure-kubernetes-at-the-edge
Expanded Security Maintenance for Applications is not enabled.
3 updates can be applied immediately.
To see these additional updates run: apt list --upgradable
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
*** System restart required ***
Last login: Thu Jul 3 07:13:37 2025 from 105.116.10.100
To run a command as administrator (user "root"), use "sudo <command>".
See "man sudo_root" for details.
#16. scp
- Secure copy
scp
allows you to securely copy files between your local computer and a remote server, or even between two remote servers. It uses SSH (Secure Shell) for encryption, so your data is always safe. It's useful for moving data to and from your cloud instances.
Syntax:
scp [options] [source] [destination]
Common options:
-
-p
: Preserves important details like the original modification times, access times, and permissions of the file you're copying. -
-r
: Recursively copies entire directories and all of their contents. -
-v
: Enables verbose mode, showing debugging output during the transfer. -
-i
: Specifies the path to a private key file for authentication.
Example:
To copy a file named cmds.txt
from your current directory to the home directory of the ubuntu
user on a server at 5.199.173.52
:
scp cmds.txt ubuntu@5.199.173.52:/home/ubuntu/
ubuntu@5.199.173.52's password:
cmds.txt 100% 2137 1.0KB/s 00:02
Confirm that the file cmds.txt
file is in ubuntu
user home directory of the server using the ls
command :
ubuntu@ubuntu:~$ ls
backup.tar.gz bin demo downloads project scripts
backups cmds.txt docker-compose.yml logs projects
#17. curl
- Transfer data with URLs
curl
is your go-to tool for making network requests. You can use it to test API endpoints, download files, or quickly check if a web server is responding.
Syntax:
curl [options] [URL]
Common options:
-
-L
: If the page you're looking for has moved, this option will automatically follow the redirect to its new location. -
-I
: Fetches only the header Information of a URL, not the full page content. -
-O
: Saves the document you fetch directly to a local file, keeping its original name. -
-u
: Specifies the username and password for server authentication. -
-d
: Sends the specified data in a POST request, typically used for submitting forms or posting to an API.
Example:
To fetch the content of a webpage:
curl https://example.com
curl https://example.com
<!doctype html>
<html>
<head>
<title>Example Domain</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<style type="text/css">
body {
background-color: #f0f0f2;
margin: 0;
padding: 0;
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", "Open Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
}
div {
width: 600px;
margin: 5em auto;
padding: 2em;
background-color: #fdfdff;
border-radius: 0.5em;
box-shadow: 2px 3px 7px 2px rgba(0,0,0,0.02);
}
a:link, a:visited {
color: #38488f;
text-decoration: none;
}
@media (max-width: 700px) {
div {
margin: 0 auto;
width: auto;
}
}
</style>
</head>
<body>
<div>
<h1>Example Domain</h1>
<p>This domain is for use in illustrative examples in documents. You may use this
domain in literature without prior coordination or asking for permission.</p>
<p><a href="https://www.iana.org/domains/example">More information...</a></p>
</div>
</body>
</html>
To fetch just the header information of the URL:
curl -I https://example.com
HTTP/2 200
content-type: text/html
etag: "84238dfc8092e5d9c0dac8ef93371a07:1736799080.121134"
last-modified: Mon, 13 Jan 2025 20:11:20 GMT
cache-control: max-age=1318
date: Thu, 03 Jul 2025 04:34:35 GMT
alt-svc: h3=":443"; ma=93600,h3-29=":443"; ma=93600
#18. ping
- Check network connectivity
ping
sends packets to a network host and listens for responses. This tells you if a host is reachable and how long it takes for your computer to get a response.
Syntax:
ping [options] [hostname_or_IP]
Common options:
-
-i
: Sets the time (in seconds) to wait between sending each packet. -
-t
: Sets the Time to Live (TTL) for outgoing packets. This is the maximum number of network hops (like routers) your packet can travel before it's discarded. -
-q
: Enables quiet output, showing only the summary statistics at the start and finish. -
-c
: Specifies the count, or the total number of ping packets to send before stopping. -
-s
: Sets the size of the data packet to be sent, measured in bytes.
Example:
Send 3 ping packets to google.com and report success/failure:
ping -c 3 google.com
PING google.com (216.58.215.110) 56(84) bytes of data.
64 bytes from waw02s17-in-f14.1e100.net (216.58.215.110): icmp_seq=1 ttl=118 time=26.4 ms
64 bytes from waw02s17-in-f14.1e100.net (216.58.215.110): icmp_seq=2 ttl=118 time=26.4 ms
64 bytes from waw02s17-in-f14.1e100.net (216.58.215.110): icmp_seq=3 ttl=118 time=26.3 ms
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 26.348/26.379/26.423/0.031 ms
To learn about more networking commands, check out our guide on Linux Network Commands.
#Permissions
Understanding file permissions and ownership is crucial for security and smooth operation in Linux. These commands let you manage who can do what with your files.
#19. chmod
- Change file permissions
chmod
is used to change the read, write, and execute permissions of files and directories. This is critical for securing your files and making scripts executable.
Syntax:
chmod [mode] [file_name]
Common options:
-
-R
: Applies the permission changes recursively to a directory and all files and subdirectories within it. -
-v
: Enables verbose mode, which prints a message for every file whose permissions are changed.
Example:
To make the deploy.sh
script inside the scripts
directory executable:
First, to check the current permissions on the file:
ubuntu@ubuntu:~$ ls -l scripts/deploy.sh
-rw-rw-r-- 1 ubuntu ubuntu 44 Jul 3 07:39 scripts/deploy.sh
The -rw-rw-r--
part shows that the owner and group can read and write, but no one can execute the file.
Next, make the file executable:
chmod +x scripts/deploy.sh
Then confirm the change by running the ls command with the -l
option so it shows the file’s permissions as well:
ubuntu@ubuntu:~$ ls -l scripts/deploy.sh
-rwxrwxr-x 1 ubuntu ubuntu 44 Jul 3 07:39 scripts/deploy.sh
Now, the output is -rwxrwxr-x
. Notice the x
has been added, confirming that the file is now executable.
You can also run the file to confirm that it is executable:
ubuntu@ubuntu:~$ ./scripts/deploy.sh
Deploy script running...
#20. chown
- Change file owner and group
chown
changes the owner and/or group of a file or directory. This is vital for ensuring that the correct users and services have access to resources.
Syntax:
chown [user]:[group] [file_name_or_directory_name]
To change the owner of a file:
chown new_owner_username my_file.txt
To change both the owner and the group:
chown new_owner_username:new_group_name another_file.txt
Common options:
-
-R
: Applies the ownership changes recursively to a directory and all files and subdirectories inside it. -
-v
: Enables verbose mode, which prints a message for every file whose ownership is processed.
Example:
To set both the owner and the group of the backups/
directory to ubuntu
:
First, confirm the ownership of the directory using the ls
command:
ubuntu@ubuntu:~$ ls -ld backups/
drwxrwxr-x 2 root root 4096 Jul 2 22:56 backups/
Change the ownership of the directory and its contents:
sudo chown -R ubuntu:ubuntu backups/
Then confirm the change by running the ls
command again:
ubuntu@ubuntu:~$ ls -ld backups/
drwxrwxr-x 2 ubuntu ubuntu 4096 Jul 2 22:56 backups/
Ownership has been successfully transferred from root
to ubuntu
.
#Conclusion
In this article, you've learned 20 Linux commands that cover file management, system monitoring, and network administration. The clear next step is to open a terminal and start practicing. That practical experience will go a long way in building your confidence.
As you become more comfortable, also keep in mind that you can learn more about any command through its manual page in the terminal. For instance, enter man ls
to find out everything about the ls command.
Cloud VPS Hosting
Starting at just $3.24 / month, get virtual servers with top-tier performance.