Linux Terminal Commands for Managing Files, Directories, Processes, and Settings

The Linux terminal is a powerful tool that allows users to execute commands directly on the operating system. In this article, we will cover essential terminal commands for managing files, directories, processes, and system settings in Ubuntu or other Linux distributions.

Navigating the File System:

  • cd: Change the current working directory. For example, cd /path/to/new/directory.
  • pwd: Prints the path of the current working directory. For example, pwd will output something like /home/user/Documents.
  • ls: Lists the files and directories in the current working directory. For example, ls -l will display a detailed list of files and directories.
  • mkdir: Creates a new directory. For example, mkdir new_directory.
  • rmdir: Removes an empty directory. For example, rmdir old_directory.
  • rm: Removes a file. For example, rm file.txt. Use with caution as it permanently deletes files.
  • mv: Moves or renames a file. For example, mv old_file.txt new_file.txt or mv old_directory new_directory2.
  • cp: Copies a file or directory. For example, cp source_file destination or cp -r source_directory destination.

Managing Directories:

  • touch: The touch command is used to create a new empty file or update the modification time of an existing file. For example, to create a new file named “newfile.txt”, use the command touch newfile.txt. If the file already exists, it will be updated with the current date and time.
  • nano/vi/vim: These are text editors used for editing files in Unix-based systems. nano is a beginner-friendly editor, while vi and vim are more advanced text editors. For example, to edit a file named “file.txt” using nano, use the command nano file.txt.
  • chmod: The chmod command is used to change the permissions of files and directories. It sets the read, write, and execute permissions for the owner, group, and others. For example, to give read, write, and execute permissions to the owner of a file named “file.txt”, use the command chmod u+rwx file.txt.
  • chown: The chown command is used to change the ownership of files and directories. It allows you to change the user or group that owns a particular file or directory. For example, to change the owner of a file named “file.txt” to the user “newuser”, use the command chown newuser file.txt.

Process Management:

  • ps: List running processes – The ps command is used to display information about currently running processes, including their process ID (PID), memory usage, and other details. For example, you can use the command ps aux | grep <process_name> to list all processes with a specific name.
  • top: Display system resources usage and running processes – The top command shows real-time information about system resources such as CPU usage, memory usage, and running processes. You can use the arrow keys to navigate through the list of processes and view detailed information about each one. For example, you can press ‘q’ to quit the top command.
  • kill: Terminate a process – The kill command is used to send signals to a running process, which can be used to terminate it or send other signals such as SIGINT (interrupt) or SIGTERM (terminate). For example, you can use the command kill <PID> to terminate a process with the given PID. If the process doesn’t terminate, you may need to use kill -9 <PID> to forcefully kill it.
  • pgrep: Search for a process by name – The pgrep command is used to search for processes based on their names or other attributes such as PIDs. For example, you can use the command pgrep <process_name> to find the PID of a running process with that name. If you want to kill the process, you can pipe the output of pgrep to kill, like this: pgrep <process_name> | xargs kill.

System Settings:

  • sudo: The sudo (Short for “Superuser DO”) command allows users to execute commands with administrative privileges. For example, if you want to install software using the package manager apt-get, but require root access, you can use sudo apt-get install <package-name>.
  • apt-get: The Advanced Package Tool (APT) is a popular package manager for Debian and Ubuntu based systems. It’s used to install, update, and remove software packages. For example, you can install the htop terminal application using sudo apt-get install htop.
  • ifconfig: The ifconfig command is used to display network interface configurations, including IP addresses, netmasks, and other details. For example, to check the IP address of your eth0 interface, you can use ifconfig eth0.
  • iptables: IPTables is a firewall configuration tool for Linux systems. It’s used to manage network traffic by defining rules that allow or block specific types of connections based on various criteria such as source and destination IP addresses, ports, and protocols. For example, you can create a rule to allow incoming SSH connections by running sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT.