DEV Community

Cover image for pwd & ls
Mohamed Yahia
Mohamed Yahia

Posted on • Updated on

pwd & ls

pwd command

  • it lets you print out the path of the current working directory
  • pwd stands for print working directory
someone@zenbook-f13:~$ pwd
/home/someone
Enter fullscreen mode Exit fullscreen mode

ls command

  • it lists files and directories(folders) inside current working directory except for hidden files

  • ls stands for list

someone@zenbook-f13:~$ ls
a  b  c  d  e  test
someone@zenbook-f13:~$ ls test
a  apple  b  banana  c  cactus  test2
Enter fullscreen mode Exit fullscreen mode
  • you could also provide an argument for the ls command to list the contents of the argument folder

ls options

  • -a lists ALL files and directories and that means including hidden files. hidden files start with a dot .
someone@zenbook-f13:~$ ls -a
.   .bash_history  .bashrc  .hushlogin  .local       .profile         .sudo_as_admin_successful  a  c  e
..  .bash_logout   .cache   .lesshst    .motd_shown  .python_history  .zcompdump                 b  d  test
Enter fullscreen mode Exit fullscreen mode
  • h lists contents in human-readable format
someone@zenbook-f13:~$ ls -lh
total 4.0K
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 a
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 b
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 c
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 d
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 e
drwxr-xr-x 3 someone someone 4.0K Oct  5 02:33 test
Enter fullscreen mode Exit fullscreen mode
  • l lists contents in long format
someone@zenbook-f13:~$ ls -l
total 4
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 a
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 b
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 c
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 d
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 e
drwxr-xr-x 3 someone someone 4096 Oct  5 02:33 test
Enter fullscreen mode Exit fullscreen mode
  • --sort=someSortingCriteria intuitive
someone@zenbook-f13:~$ ls -l --sort=time
total 4
drwxr-xr-x 3 someone someone 4096 Oct  5 02:33 test
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 d
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 e
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 a
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 b
-rw-r--r-- 1 someone someone    0 Oct  3 19:07 c
Enter fullscreen mode Exit fullscreen mode

Top comments (0)