GNU/Linux Command-Line Tools Summary
Prev
Chapter 7. Working with the file-system
Next
7.2. Working with files and folders
- mkdir
- rm
- rmdir
- mv
- cp
Make a directory. Use mkdir -p to create subdirectories automatically.
Directories are Folders
Directories are sometimes called folders in other operating systems (such as Microsoft Windows)
Examples:
mkdir -p /home/matt/work/maths
This would create the directories "work" and "maths" under matt's home directory (if matt's home directory didn't exist it would create that too).
mkdir foo
This would create a directory in the current path named "foo".
Remove/delete a file(s) or directories(s). You can use standard wildcards with this command Section 20.4.1 .
Command syntax:
rm -options file_or_folder
You can of course use standard wildcards to delete multiple files or multiple directories and files.
Use the -R or -r option to remove recursively, this removes everything within subdirectories. Also try the -f option to force removal (useful when you don't want to be prompted).
Disabling Aliases (per execution)
On some systems such as Mandrake an alias will send rm to rm -i (prompting you for every file you wish to delete). To override this use: \rm -R directory (using the \ disables the alias for this run only)
Remove an empty directory. If you want to remove a directory with files in it type " rm -R directory", read above for information on rm -R
Command syntax:
rmdir directory
This will only remove directory if it's empty otherwise it will exit with an error message.
Move a file or a directory to a new location or rename a file/directory.
Rename example:
mv filename1 filename2
Renames filename1 to filename2.
To move a file or directory, simply type:
mv original_file_or_folder new_location
Note that this command can use standard wildcards Section 20.4.1 to move files (not for renaming).
Move and rename
Note that you can also move and rename a file in a single command. The difference is with the destination (right hand side) you change the filename to the new name of the file.
For example typing:
mv /etc/configuration.txt /home/joe/backupconfig
This would move the file "configuration.txt" to /home/joe/ and rename it "backupconfig"
Copy a file. Has a number of useful options, such as -R (or -r ) which recursively copies directories and subdirectories.
Command syntax:
cp -options file_or_files new_location
Examples:
cp file1 file2
Simply copy file1 to file2 (in the same directory).
cp /tmp/file1 ~/file2 /mnt/win_c
Where the last option is the directory to be copied to. The above
* License

