{:check ["true"]}
ls commandLooking around in the filesystem can be done by the ls command.
$ ls
assignments README.md
The command comes with many options.
split=8
$ ls -F assignments/ README.mdCommand line options are very typical for UNIX commands. The
-Foption instructslsto show directories with the/indicator.
Command line options can be combined.
split=8
\$ ls -a -F ./ ../ assignments/ README.md \$ ls -aF ./ ../ assignments/ README.mdThe
-aoption shows all files, including hidden files (which have names starting with.).Multiple options can be provided to the command.
We can show specific files.
split=8
\$ ls K.png main main.c main.o MakefileHere is the list of files in some directory.
split=8
\$ ls main* main main.c main.oWe can use wildcards to selectively show certain files.
split=8
$ ls assignments/assignment_1 assignments/assignment_2 assignments/assignment_1: K.png assignments/assignment_2: main main.c main.o MakefileWe can also list the contents of one or more specific directories.
Each file has many metadata. We can use the -l to indicate we want
the long format.
split=8
$ ls -l total 32 -rwxrwxr-x 1 kenpu kenpu 16688 Aug 13 13:28 main -rw-rw-r-- 1 kenpu kenpu 64 Aug 13 13:12 main.c -rw-rw-r-- 1 kenpu kenpu 1672 Aug 13 13:28 main.o -rw-rw-r-- 1 kenpu kenpu 66 Aug 13 13:13 Makefile
total 32shows that there are 32 blocks consumed.-rw-rw-r--is the read-write-execute permissions of the file with respect to the user, the group, and everyone.kenpu kenpuis the owner and the owner group.16688is the file size in bytes.Aug 13 13:28is the last modification time.
We can show the entire subtree of a directory using the recursive option.
$ ls -R
.:
assignments README.md reports
./assignments:
assignment_1 assignment_2
./assignments/assignment_1:
K.png
./assignments/assignment_2:
main main.c main.o Makefile
./reports:
Other useful options:
-1: display in single column.-h: display in more human friendly format.-S: sort files from largest to smallest.lsYou can refer to the documentation:
box