Featured image of post Linux Commands

Linux Commands

Commonly used Linux terminal commands

Commands for File and Directory Operations in Linux

File and directory operations in Linux mainly involve the following commands:

  1. ls - List directory contents

    • Usage example: ls -l (list file or directory details in long format)
  2. cd - Change the current directory

    • Usage example: cd /home (switch to the /home directory)
  3. pwd - Display the path of the current directory

    • Usage example: pwd (display the full path of the current working directory)
  4. mkdir - Create a new directory

    • Usage example: mkdir new_dir (create a new directory named new_dir)
  5. rmdir - Remove an empty directory

    • Usage example: rmdir empty_dir (remove the empty directory named empty_dir)
  6. rm - Remove files or directories

    • Usage example: rm file.txt (remove the file named file.txt)
    • Advanced usage: rm -r dir (recursively remove the directory named dir and its contents)
  7. cp - Copy files or directories

    • Usage example: cp source.txt dest.txt (copy source.txt to dest.txt)
    • Advanced usage: cp -r source_dir dest_dir (recursively copy a directory)
  8. mv - Move or rename files or directories

    • Usage example: mv old_name.txt new_name.txt (rename old_name.txt to new_name.txt)
    • Advanced usage: mv file.txt /home/user/ (move file.txt to the specified directory)
  9. touch - Create an empty file or modify a file’s timestamp

    • Usage example: touch new_file.txt (create an empty file named new_file.txt)
  10. chmod - Change the permissions of a file or directory

    • Usage example: chmod 755 file.txt (change the permissions of file.txt so that the owner can read, write, and execute, and the group and other users can read and execute)
  11. chown - Change the owner of a file or directory

    • Usage example: chown user:group file.txt (change the owner of file.txt to user and the group to group)

These commands are the foundation of file and directory management in Linux systems, and mastering them is essential for effective system administration.

Linux Process Management Commands

Process management in Linux mainly involves the following commands:

  1. ps - Display a snapshot of current processes

    • Usage example: ps aux (display information about all processes)
  2. top - Dynamically display process information

    • Usage example: top (display system process information in real time)
  3. htop (requires separate installation) - An enhanced version of the top command, offering a friendlier interface and more information

    • Usage example: htop (display system process information in real time with a friendlier interface)
  4. kill - Send a signal to a specified process

    • Usage example: kill -9 1234 (send the SIGKILL signal to the process with PID 1234, forcibly terminating it)
  5. pkill - Send a signal based on process name

    • Usage example: pkill nginx (send the SIGTERM signal to all processes named nginx)
  6. killall - Kill all processes based on process name

    • Usage example: killall nginx (kill all processes named nginx)
  7. nohup - Run a command in the background so that it continues even if the terminal is closed

    • Usage example: nohup command & (run command in the background and ignore the hangup signal)
  8. bg - Resume a job that was suspended in the background

    • Usage example: first use Ctrl+Z to suspend a process, then use the bg command to continue running it in the background
  9. fg - Bring a background job to the foreground to continue running

    • Usage example: fg (bring the most recent background job to the foreground to continue running)
  10. jobs - Display all jobs in the current session and their status

    • Usage example: jobs (list all jobs in the current session)
  11. nice - Set the priority of a new process

    • Usage example: nice -n 10 command (start command with priority 10)
  12. renice - Modify the priority of an existing process

    • Usage example: renice 10 -p 1234 (set the priority of the process with PID 1234 to 10)

These commands are the foundation of process management in Linux systems; with them, you can effectively monitor, control, and adjust processes on the system.

Commands related to user and user group management in Linux systems include:

  1. useradd - Add a new user

    • Usage example: useradd username (add a new user)
  2. userdel - Delete a user

    • Usage example: userdel username (delete a user)
  3. usermod - Modify a user account

    • Usage example: usermod -l newname oldname (change the username from oldname to newname)
  4. passwd - Change a user’s password

    • Usage example: passwd username (change the password of the specified user)
  5. adduser (on some distributions) - A friendlier command for adding users than useradd, usually offering more options

    • Usage example: adduser newusername (add a new user interactively)
  6. groupadd - Add a new user group

    • Usage example: groupadd groupname (add a new user group)
  7. groupdel - Delete a user group

    • Usage example: groupdel groupname (delete a user group)
  8. groupmod - Modify a user group

    • Usage example: groupmod -n newname oldname (change the user group name)
  9. gpasswd - Manage the /etc/group file

    • Usage example: gpasswd -a username groupname (add a user to a user group)
  10. id - Display a user’s UID and GID as well as the groups they belong to

    • Usage example: id username (display information about the specified user)
  11. who - Display currently logged-in users

    • Usage example: who (display all users currently logged in to the system)
  12. w - Display currently logged-in users and the commands they are running

    • Usage example: w (display more detailed information about currently logged-in users)
  13. su - Switch user identity

    • Usage example: su - username (switch to the specified user; the - parameter means the user’s environment variables are also switched to those of the target user)
  14. sudo - Execute a command as another user (root by default)

    • Usage example: sudo command (execute command as root)
  15. chown - Change the owner of a file or directory

    • Usage example: chown username:groupname file (change the owner and group of a file)
  16. chmod - Change the permissions of a file or directory

    • Usage example: chmod 755 file (change file permissions)

These commands are the foundation of user and user group management in Linux systems; with them, you can effectively manage user accounts and permissions on the system.

Other Linux Commands

  1. echo - Display a string
    • Usage example: echo “Hello,everyone!” (display the string “Hello,everyone!”
  2. cal - Display a calendar
    • Usage example: cal (display the calendar for the current month)
  3. date - Display and set the system date and time
    • Usage example: date 08211550 (change the time to August 21st, 3:50 PM)
  4. clear - Clear the screen
    • Usage example: clear
Built with Hugo and Stack
Built with Hugo
Theme Stack designed by Jimmy