ls
- List Directory Contentsls
command is used to list the files and directories in the current working directory or a specified directory.ls
- To list the contents of a specific directory, for example, `/home/user/Documents`:
ls /home/user/Documents
- To list all files including hidden files (files starting with a dot `.`):
ls -a
ls
is often used right after changing directories to see what’s inside.ls -l
) to get detailed information about files such as permissions, owner, group, size, and modification time.cd
- Change Directorycd
command is used to change the current working directory.Documents
directory:cd Documents
- To move up one level in the directory tree:
cd..
- To go back to the home directory:
cd ~
cd
to move to the project directory.mkdir
- Make Directorymkdir
command is used to create new directories.new_project
:mkdir new_project
- To create multiple directories at once, for example, `dir1`, `dir2`, and `dir3`:
mkdir dir1 dir2 dir3
- To create a directory with its parent directories if they don't exist:
mkdir -p parent_dir/child_dir
mkdir
to create the necessary directory structure.rm
- Remove Files and Directoriesrm
command is used to remove files and directories.test.txt
:rm test.txt
- To remove a directory and all its contents recursively:
rm -r my_directory
- To remove files and directories without prompting for confirmation:
rm -rf my_directory
rm
is used.-rf
option as it can permanently delete important data.grep
- Global Regular Expression Printgrep
command is used to search for a specified pattern in a file or a stream of text.log.txt
:grep "error" log.txt
- To perform a case - insensitive search:
grep -i "error" log.txt
- To search recursively in a directory for a pattern:
grep -r "error" /var/log
grep
to search for specific strings in source code files, log files, etc.grep
with other commands using pipes (|
) for more complex text processing.sed
- Stream Editorsed
command is used to perform basic text transformations on an input stream (a file or input from a pipeline).file.txt
and print the result:sed 's/old/new/g' file.txt
- To save the changes back to the original file:
sed -i 's/old/new/g' file.txt
sed
is often used for mass - replacing strings in configuration files.sed
command first without the -i
option to make sure the changes are correct.ps
- Process Statusps
command is used to report a snapshot of the current processes.ps
- To list all processes on the system:
ps -ef
ps
to check if a particular application or service is running.ps
in combination with grep
to quickly find a specific process, e.g., ps -ef | grep my_app
.kill
- Send a Signal to a Processkill
command is used to send a signal to a process. By default, it sends the TERM
(terminate) signal.1234
:kill 1234
- To send a `KILL` signal (force - terminate) to a process:
kill -9 1234
kill
to terminate it.TERM
signal first, as it allows the process to clean up resources properly.ping
- Send ICMP Echo Requestsping
command is used to test the reachability of a host on an Internet Protocol (IP) network.google.com
:ping google.com
- To limit the number of ping requests to 5:
ping -c 5 google.com
ping
to check if a server or a network device is online.ping
as an initial step when diagnosing network connectivity issues.ssh
- Secure Shellssh
command is used to establish a secure connection to a remote server.user
and the server address example.com
:- To use a specific port (e.g., port 2222) for the SSH connection:
ssh -p 2222 [email protected]
ssh
to access remote servers for deployment, maintenance, etc.apt
(Debian - based Systems)apt
command is used for package management on Debian - based Linux distributions such as Ubuntu.sudo apt update
- To upgrade all installed packages:
sudo apt upgrade
- To install a new package, for example, `nginx`:
sudo apt install nginx
- To remove a package:
sudo apt remove nginx
apt
to install development tools, libraries, and servers.Mastering essential Linux command - line commands is a crucial skill for developers. These commands provide a powerful and efficient way to interact with the operating system, manage files, process text, handle processes, work with networks, and manage packages. By understanding the fundamental concepts, usage methods, common practices, and best practices of these commands, developers can significantly improve their productivity and become more proficient in their work.