read

Essential Linux Commands for Everyday Use

Linux is a powerful operating system widely used in server environments and by developers worldwide. One of the key strengths of Linux is its command-line interface (CLI), which allows users to perform a wide variety of tasks efficiently. Below are some handy Linux commands with detailed explanations to help you navigate, manage files and directories, and perform network-related tasks.

Navigation

Command: cd ./

The cd command stands for "change directory." It is used to change the current working directory in the terminal.

  • ./ refers to the current directory.
  • To move to a specific directory, you can use cd /path/to/directory.
  • For example, cd /home/user/Documents will navigate to the Documents directory within the user's home directory.

Example:

cd /home/user/Documents

Creating Directories

Command: mkdir mdir /mnt/media

The mkdir command is used to create new directories.

  • mdir is a placeholder for the directory name you want to create.
  • /mnt/media is the path where the new directory will be created.

Example:

mkdir /mnt/media

Removing Directories

Command: rmdir /mnt/media

The rmdir command is used to remove empty directories.

  • /mnt/media is the directory you want to remove. Note that rmdir only works on empty directories. To remove a directory with contents, use rm -r /path/to/directory.

Example:

rmdir /mnt/media

Mounting Directories over NFS

Command: mount -t nfs 192.168.1.1:/data /mnt/media

The mount command is used to mount file systems.

  • -t nfs specifies the type of file system to mount, in this case, NFS (Network File System).
  • 192.168.1.1:/data is the NFS server and the directory to be mounted.
  • /mnt/media is the local directory where the remote file system will be mounted.

Example:

mount -t nfs 192.168.1.1:/data /mnt/media

Disconnecting a Mount

Command: umount /mnt/media

The umount command is used to unmount file systems.

  • /mnt/media is the directory you want to unmount.

Example:

umount /mnt/media

Finding Files and Folders

Command: find -name nameofthefile.txt

The find command is used to search for files and directories.

  • -name specifies that you are searching by name.
  • nameofthefile.txt is the name of the file you are looking for. You can use wildcards, such as *.txt, to search for all text files.

Example:

find /home/user -name nameofthefile.txt

Additional Useful Commands

Listing Files and Directories

Command: ls

The ls command lists the contents of a directory.

  • To list all files, including hidden files, use ls -a.
  • To list files with detailed information, use ls -l.

Example:

ls -la /home/user

Detailed Listing of Files and Directories

Command: ls -l

The ls -l command lists files and directories with detailed information such as permissions, number of links, owner, group, size, and timestamp.

Example:

ls -l /home/user

Output:

drwxr-xr-x 2 user user 4096 Jun  1 10:00 Documents
-rw-r--r-- 1 user user  123 Jun  1 10:00 file.txt

Copying Files and Directories

Command: cp

The cp command copies files and directories.

  • To copy a file, use cp source_file destination_file.
  • To copy a directory and its contents, use cp -r source_directory destination_directory.

Example:

cp /home/user/file.txt /home/user/backup/

Moving Files and Directories

Command: mv

The mv command moves or renames files and directories.

  • To move a file, use mv source_file destination_file.
  • To rename a file, use mv old_name new_name.

Example:

mv /home/user/file.txt /home/user/Documents/

Deleting Files and Directories

Command: rm

The rm command removes files and directories.

  • To remove a file, use rm file_name.
  • To remove a directory and its contents, use rm -r directory_name.

Example:

rm /home/user/file.txt

Viewing and Editing Files

Viewing File Contents

Command: cat

The cat command displays the contents of a file.

Example:

cat /home/user/file.txt

Editing Files

Command: nano or vi

The nano and vi commands are used to edit files from the command line.

  • nano is user-friendly and suitable for beginners.
  • vi (or vim) is more powerful but has a steeper learning curve.

Example:

nano /home/user/file.txt
vi /home/user/file.txt

System Information and Monitoring

Checking Disk Usage

Command: df

The df command reports file system disk space usage.

  • Use df -h for human-readable format.

Example:

df -h

Checking Memory Usage

Command: free

The free command displays the amount of free and used memory in the system.

  • Use free -h for human-readable format.

Example:

free -h

Monitoring System Processes

Command: top

The top command provides a real-time view of system processes and resource usage.

Example:

top

Network Management

Checking Network Configuration

Command: ifconfig

The ifconfig command displays network interface configuration.

Example:

ifconfig

Checking Network Connectivity

Command: ping

The ping command checks the network connectivity to a specified host.

Example:

ping google.com

Conclusion

These commands are just the tip of the iceberg when it comes to the powerful capabilities of the Linux command line. Mastering these basic commands will enable you to navigate and manage your system more efficiently. As you become more comfortable with the CLI, you’ll discover many more commands and options that can help automate and streamline your workflow.

Blog Logo

Vincentde Koning

The world is a playground!


Published

Image

DE KONING

Projects, Adventures and Experiments

Back to Overview