- Starting Up the Terminal
- Getting Started
- Building Pipelines
- Running Commands as Superuser
- Finding Help
- Moving around the Filesystem
- Manipulating Files and Folders
- System Information Commands
- Searching and Editing Text Files
- Dealing with Users and Groups
- Getting Help on the Command Line
- Searching for Man Files
- Using Wildcards
- Executing Multiple Commands
- Moving to More Advanced Uses of the Command Line
Manipulating Files and Folders
You can manipulate files and folders with the following commands.
cpcommand makes a copy of a file for you. For example,
foomakes an exact copy of the file whose name you entered and names the copy foo, but the first file will still exist with its original name.
mvcommand moves a file to a different location or renames a file. Examples are as follows:
mv file foorenames the original file to foo.
mv foo ~/Desktopmoves the file foo to your desktop directory but does not rename it. You must specify a new filename to rename a file. After you use
mv, the original file no longer exists, but after you use
cp, as above, that file stays and a new copy is made.
- To save on typing, you can substitute
~in place of the home directory, so
/home/username/picturesis the same as
rm: Use this command to remove or delete a file in your directory, as in
rm file.txt. It does not work on directories that contain files, which must first be emptied and may then be deleted using the
rmdircommand. There are some advanced cases where you may use
rmto remove directories, but discussing those are beyond the intent of this chapter.
lscommand shows you the files in your current directory. Used with certain options, it lets you see file sizes, when files where created, and file permissions. For example,
ls ~shows you the files that are in your home directory.
mkdircommand allows you to create directories. For example,
mkdir musiccreates a music directory.
chmodcommand changes the permissions on the files listed. Permissions are based on a fairly simple model. You can set permissions for user, group, and world, and you can set whether each can read, write, and/or execute the file. For example, if a file had permission to allow everybody to read but only the user could write, the permissions would read
rwxr—r—. To add or remove a permission, you append a
-in front of the specific permission. For example, to add the capability for the group to edit in the previous example, you could type
chmod g+w file.
chowncommand allows the user to change the user and group ownerships of a file. For example,
sudo chown jim filechanges the ownership of the file to Jim.