The Linux file system follows a hierarchical structure, with the root directory (/
) at the top. Some important directories include:
/bin
: Contains essential binary executables./etc
: Holds system configuration files./home
: Stores user home directories./var
: Contains variable data, such as logs and spool files.Linux uses a permission system to control access to files and directories. There are three types of permissions: read (r
), write (w
), and execute (x
). Each file and directory has permissions for the owner, group, and others. For example, the permission rwxr-xr-x
means the owner has read, write, and execute permissions, while the group and others have read and execute permissions.
pwd
: Print the current working directory.pwd
cd
: Change the current working directory.cd /home/user/Documents
ls
: List the contents of a directory.ls
ls -l
: List the contents of a directory in long format, showing permissions, owner, group, size, and modification time.ls -l
touch
: Create a new empty file.touch newfile.txt
mkdir
: Create a new directory.mkdir new_directory
rm
: Remove a file or directory.rm newfile.txt
rm -r
: Remove a directory and its contents recursively.rm -r new_directory
cp
: Copy a file or directory.cp file.txt /home/user/Documents
mv
: Move or rename a file or directory.mv file.txt newname.txt
cat
: Concatenate and display the contents of a file.cat file.txt
grep
: Search for a pattern in a file.grep "keyword" file.txt
sed
: Stream editor for filtering and transforming text.sed 's/old/new/g' file.txt
awk
: A powerful text processing language.awk '{print $1}' file.txt
ps
: List currently running processes.ps aux
top
: Display real-time information about running processes.top
kill
: Terminate a process.kill -9 1234
history
: Display the command history.history
!!
: Repeat the last command.!!
Ctrl + R
: Search the command history interactively.|
): Connect the output of one command to the input of another command.ls -l | grep ".txt"
>
): Redirect the output of a command to a file.ls > file_list.txt
>>
): Append the output of a command to a file.echo "New line" >> file.txt
Wildcards are special characters used to represent one or more characters in a file or directory name.
*
: Matches any number of characters.ls *.txt
?
: Matches a single character.ls file?.txt
#!/bin/bash
echo "Hello, World!"
hello.sh
, make it executable, and run it.chmod +x hello.sh
./hello.sh
#!/bin/bash
if [ -f "file.txt" ]; then
cat file.txt
else
echo "File does not exist."
fi
Mastering the Linux command line is a valuable skill that can greatly enhance your productivity and control over your Linux systems. By understanding the fundamental concepts, usage methods, common practices, and best practices, you can become proficient in using the command line to perform a wide range of tasks. Remember to practice regularly and explore more advanced commands and techniques to further improve your skills.