Basic List & Directory Commands in Linux

Basic List & Directory Commands in Linux

If you're just starting with Linux, you must know how to work with files and directories. Here’s a quick guide on some of the most commonly used commands to list and manage directories.

1. Listing Commands

  • ls: Lists the files and directories in the current.```bash

Example:?

-Command: ls

-Output: file1.txt? file2.txt? directory1

  • ls -l: Lists files and directories in long format (shows details like file permissions, owner, size, and modification date).

Example:

-Command: ls -l?

-Output: drwxrwxr-x 2 ubuntu ubuntu 4096 Oct 15 16:27 devops1

-rw-rw-r-- 1 ubuntu ubuntu 0 Oct 15 16:28 first.txt

  • ls -a: Lists all files, including hidden files (files that start with a dot .).

Example:

-Command: ls -a

-Output: . .. .bash_history .bash_logout .bashrc .cache .lesshst .profile .ssh .sudo_as_admin_successful .viminfo devops

  • ls -lh: Lists files with sizes in human-readable format (KB, MB, GB, etc.).

Example:

-Command: ls -Ih

-Output: total 4.0K

drwxrwxr-x 3 ubuntu ubuntu 4.0K Oct 15 16:28 devops

  • ls -R: Recursively lists files in the current directory and all subdirectories.

Example:

-Command: ls -R

-Output: .:

devops

./devops:

devops1 first.txt

./devops/devops1:

second.txt

2. Directories Commands

  • pwd (Print Working Directory): Displays the full path of the current directory.

Example:

Command: pwd

Output: /home/ubuntu/devops

  • cd (Change Directory): Changes to a different directory.

Example:

Command: cd devops1

Output: ubuntu@ip-111-31-31-515:~/devops/devops1$

  • cd ..: Moves up one directory level (to the parent directory).

Example:

Command: cd ..

Output: ubuntu@ip-111-31-31-515:~/devops$

  • cd ~ or cd: Moves to the home directory of the user.

Example:

Command: cd ~

Output: ubuntu@ip-111-31-31-515:~$

  • mkdir (Make Directory): Creates a new directory.

Example:

Command: -mkdir new_folder

-ls

Output: devops1 first.txt new_folder

  • rmdir (Remove Directory): Removes an empty directory.

Example:

Command: rmdir new_folder

-ls

Output: devops1 first.txt

  • rm -r: Removes a directory and its contents (use carefully, as this will delete everything inside the directory).

Example:

Command: rm -r new_folder

ubuntu@ip-111-31-31-515:~/devops/new_folder$ ls

third.txt

Output: ubuntu@ip-111-31-31-515:~/devops$ ls

devops1 first.txt

These basic list and directory commands are just a starting point for managing files and directories in Linux. They help you navigate and organize your system more efficiently. By exploring more options and practicing, you’ll gradually become proficient in using the Linux command line.

要查看或添加评论,请登录

Shaikh Zahid的更多文章

社区洞察

其他会员也浏览了