This page is intended to help the Linux newbie come up to speed on core file handling commands including file permissions. Brought to you by Mark Rais, our senior editor. To read comands for Directories please click here.
Included in this section are the commands needed to copy, delete, move, and rename files. Security and permissions are also reviewed below in the chmod command.
Manipulating Files - Linux Commands
chmod command allows you to alter access
rights to files and directories. All files and
directories have security permissions that grant the user
particular groups or all other users access.
To view your files' settings, at the shell prompt type: ls -alt
You should see some files with the following in front of them (an example follows):
drwxrwsr-x 7 reallyli reallyli 1024 Apr 6 14:30 .
drwxr-s--x 22 reallyli reallyli 1024 Mar 30 18:20 ..
d-wx-wx-wx 3 reallyli reallyli 1024 Apr 6 14:30 content
drwxr-xr-x 2 reallyli reallyli 1024 Mar 25 20:43 files
What do the letters mean in front of the files/directories mean?
r indicates that it is readable (someone can view the files contents)
w indicates that it is writable (someone can edit the files contents)
x indicates that it is executable (someone can run the file, if executable)
- indicates that no permission to manipulate has been assigned
When listing your files, the first character lets you know whether youre looking at a file or a directory. Its not part of the security settings. The next three characters indicate Your access restrictions. The next three indicate your group's permissions, and finally other users' permissions.
Use chmod followed by the permission you are
changing. In very simple form this would be:
Still confused? Use the table above to define the settings for the three "users." In the command, the first number refers to your permissions, the second refers to group, and the third refers to general users.
Typing the command: chmod 751 filename
gives you full access, the group read and execute, and all others execute only permission.
cp followed by the name of an existing file and the name
of the new file.
cp newfile newerfile
To copy a file to a different directory (without changing th
e files name), specify the directory instead of the new
cp newfile testdir
To copy a file to a different directory and create a new file name, you need to specify a directory/a new file name. Ex:
cp newfile testdir/newerfile
cp newfile ../newerfile
The .. represents one directory up in the hierarchy.
file followed by the name of an existing file in the directory.
OUTPUT: MS-DOS executable (EXE)
This command allows you to figure out what the file type is and how to use it. For instance the command will tell you whether it is an executable, a compressed file and which type, or something unusual.
This command is simplistic, but often can allow you to determine why a file does not respond the way you expect.
mv followed by the current name of a file and the new
name of the file.
mv oldfile newfile
followed by the name of a file and the new directory
where you'd like to place the file. Ex:
|rm||Type rm followed by the name of
a file to remove the file.
Use the wildcard character to remove several files at once. Ex:
This command removes all files beginning with n.
Type rm -i followed by a filename if youd like to be prompted before the file is actually removed. Ex:
rm -i newfile
rm -i n*
By using this option, you have a chance to verify the removal of each file. The -i option is very handy when removing
a number of files using the wildcard character *.
This list only has items related to files, but this link will take you to the page related to commands for directories.