A shell is a command - line interpreter that allows users to interact with the operating system. In Linux, there are several popular shells such as Bash (Bourne - Again SHell), Zsh (Z Shell), and Fish. Bash is the most commonly used shell and is the default on many Linux distributions.
The Linux file system follows a hierarchical structure. The root directory, denoted by /
, is the top - level directory. Other important directories include:
/home
: Contains user home directories./bin
: Holds essential user binary programs./sbin
: Contains system binary programs./etc
: Stores system configuration 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
). These permissions are set for three different user classes: the owner, the group, and others. For example, the permission string rwxr - xr - x
means the owner has read, write, and execute permissions, the group has read and execute permissions, and others have read and execute permissions.
pwd
: Print the current working directory.pwd
ls
: List the contents of a directory. You can use options like -l
for a long listing and -a
to show hidden files.ls -la
cd
: Change the current working directory.cd /home/user/Documents
touch
: Create a new empty file.touch newfile.txt
mkdir
: Create a new directory.mkdir new_directory
rm
: Remove a file or directory. Use the -r
option to remove directories recursively.rm -r new_directory
cat
: Concatenate and display the contents of a file.cat file.txt
grep
: Search for a pattern in a file.grep "example" file.txt
sed
: Stream editor for filtering and transforming text.sed 's/old_text/new_text/g' file.txt
useradd
: Add a new user.useradd newuser
passwd
: Set or change a user’s password.passwd newuser
groupadd
: Create a new group.groupadd newgroup
ps
: Display information about currently running processes.ps aux
top
: Display real - time information about system processes.top
kill
: Send a signal to a process to terminate it.kill -9 <process_id>
tail
: Display the last few lines of a log file.tail -n 20 /var/log/syslog
journalctl
: View systemd journal logs.journalctl -u service_name
Aliases are shortcuts for frequently used commands. You can define aliases in your shell configuration file (e.g., .bashrc
). For example, to create an alias for ls -la
:
alias lla='ls -la'
Write shell scripts to automate repetitive tasks. For example, a simple script to backup a directory:
#!/bin/bash
SOURCE_DIR="/home/user/Documents"
BACKUP_DIR="/backup"
DATE=$(date +%Y%m%d)
tar -czf $BACKUP_DIR/backup_$DATE.tar.gz $SOURCE_DIR
Use the history
command to view your command history. You can also use the !
operator to repeat commands. For example, !!
repeats the last command.
When accessing a Linux system remotely, use SSH (Secure Shell) instead of Telnet. SSH encrypts the data transmitted between the client and the server, providing a secure connection.
The Linux command line is a powerful and versatile tool for system administrators. By understanding the fundamental concepts, mastering the usage methods, following common practices, and implementing best practices, system administrators can manage Linux systems more efficiently and effectively. Continuous learning and practice are key to becoming proficient in using the Linux command line.