...
Moving and renaming files (mv
command)
When you need to move rather than copy files from one location to another, use the mv
(move) command. The command syntax is very similar to the cp
command, in that you must provide a source file and target destination:
mv /path/to/source/file.abc /path/to/target/directory/
The mv
command is also used to rename files. When used this way, the mv
command "moves" a file from one path to another, even if that path is within the same folder. To rename a file, add the new name to the end of the target destination:
mv /path/to/source/file.abc /path/to/source/newFile.abc
You can combine these two uses of mv
to move a file to a new directory and rename it at the same time:
mv /path/to/source/file.abc /path/to/target/directory/newFile.abc
Calculating directory size (du
command)
The du
(disk usage) command calculates the size of a file, directory, or set of directories. To calculate the size of an individual file, simply run du
followed by the path to the file:
By default, du
displays file size in bytes. Use the -h
option to display the size in a more human-readable format:
Running du
followed by the path to a directory will calculate the size of all subdirectories within that location:
Add the -a
option to calculate the size of subdirectories and files within a given directory:
Use the -s
option to calculate the total size of a directory and its contents:
Calculating disk usage (df
command)
...