Linux ls commands with examples


Linux ls commands with examples

1. Command to view the Content of the last Edited File Using ls command

#ls -1tr | tail -1 | xargs cat

2. Commands to list only folders

#ls -F | grep /
#ls -l | grep ^d
#ls -l | sed -n ‘/^d/p’

3. Command to view only files in the folder

#ls -l | sed -n ‘/^d/!p’
#ls -l | sed ‘/^total/d’ | sed -n ‘/^d/!p

4. Command to view only files and arrange it in ascending order according to file Size
#ls -lFSh | grep -v ‘/’ | sed -n ‘/total/!p’

5. Commands to view all hidden files
#ls -a
#ls -A

6. Commands to view last edited file

#ls -1tr

7. Command to view size of a file

#ls -lh test.pdf

8. Command to view the files based on its size in acending order

#ls -lhS | sed -n ‘/^d/!p’

9. Command to view all the file inside a folder recursively

#ls -R

10. Command to display one file per line

#ls -1

11.Command to do reverse search in ls
#ls -r

Leave a Reply

Your email address will not be published. Required fields are marked *