Chapter 1 Flashcards
(27 cards)
List Files and Directories
ls
List All Files
ls -a
List Files in Long Form
ls -l
List Files with Human Readable Sizes
ls -h
List files, sorted by size
ls -S
List files, sorted by last modified time
ls -t
List files, reverse sorted
ls -r
Hard links vs a symbolic link?
Hard links create an identical copy of the linked file on disk, that gets updated automatically as the source file gets updated. That means if the content of the source is changed, so will the target file.
Unfortunately hard links do not work for directories. To create a link to a directory, we can use the -s flag to create a symbolic link. This can also be used for linking to files as well, not just directories.
Symbolic links can also link to files or directories on other file systems.
Link from source to linked file
ln a.txt b.txt
Force a link to be created
ln -f a.txt b.txt
Create a symbol link
ln -s a.txt b.txt
Navigate up a directory
cd ..
Navigate to home directory
cd
Create a directory
mkdir foo
Create intermediate directories
mkdir -p a/b/c
Create directory with verbose output (useful in shell scripts)
mkdir -v a
Copy a single file
cp a.txt b.txt
Copy multiple files
cp a.txt b.txt foo
or
cp *.txt foo
Last argument must be a directory
Copy with verbose output
cp -v a.txt b.txt
Copy a directory’s contents
cp -R foo bar
Force copying of a file, e.g. if you don’t have permission to do so.
cp -f a.txt b.txt
Copy with confirmation of overwriting each file
cp -i a.txt b.txt
Delete a file, with verbose output
rm -v a.txt
When would you use cp
followed by rm
, instead of only mv
?
This can be useful when trying to move a file across file systems, as the mv command doesn’t support that.