File Manipulation and Modification
Files in UNIX are documents which contain static information or applications which can be executed. Each file has some information associated with it; the owner of the file, the group associated with the file, size of the file, location of the file, creation and last modified dates, and file permissions. To see most of this information use thels al command described above. Text files may be viewed with the commands described below. If the output of this command looks like gibberish (and may be accompanied by beeps) it is probably a binary format file.
more [file name]
Returns the contents of the text file specified in pages. After each page has been displayed pressing<Q> will exit and pressing any other key will display the next page.
cat [file name]
Returns the contents of the text file all at once.
Each file (and folder as well) has its own set of permissions to regulate how, and by whom the particular file is modified, manipulated and executed. There are three aspects and three user levels of permissions with each file. The three aspects are read, write and execution privileges. The three user levels are the user (the owner), group, and everyone on the system. Below are some examples of permissions combinations on files in the notation returned by thels al command described above.
rwxrwxrwxUser, group and everyone can read write and execute the file.
rw-rw-rw-User, group and everyone can read and write this file.
rw-r--r--User can read and write to this file, but the group and everyone else can only read it.
rwx------User can read, write and execute this file but no one else can.
Permissions for a particular file may be changed if you (the user) has write permissions for that file. To do so use thechmod command described below.
chmod [levels]+[permissions] [file name]
chmod uga+rwx test.txt
Changes the permissions of the specified files using the levels and permissions designated. The levels are designated byu, g, and/or a, for user, group, and all. The permissions are designated by r, w, and/or x, for read, write, and execute.
Creating Files and Folders
Often files are created by applications or commands. To create a new text file use thejot command, if youre in an X-windows GUI environment, or the vi command if you are using a remote terminal. jot is much easier to use than vi and should be self explanatory. To create a new directory use the command mkdir, described below.
jot [file name]
vi [file name]
Creates a new file with file name or edits the file if it exists already.jot is too simple to describe here and vi is too complex. For more notes on either see their man pages.
mkdir [folder name]
Creates a new folder in the present working directory. For instance if the example above were executed in the directory/usr/people/mcdermoj, a new folder would be created having the path /usr/people/mcdermoj/images/.
Copying, Moving or Removing Files and Folders
To copy or move files from one place to another or to change the name of a file use the commandscp or mv described below. To remove files use the rm command.
Note:Be very careful using these commands, especially the rm command, since in command line UNIX there are no failsafes to verify if you really want to go through with your command. It can be very easy to delete files or folders by accident, especially when using wildcards in the file name designation.
cp [from filename] [target filename]
mv [from filename] [target filename]
cp test.txt test_backup.txt
mv test.txt /usr/people/mcdermoj/test.txt
Copies (cp) or moves (mv) the first file speicifed to the second filename specified. This will create, or overwrite the target file. Using a period for the target file will leave the filename unchanged (e.g. mv test.txt /usr/people/mcdermoj/.)
rm [file name]
Removes the specified file permanently.
rm R [folder name]
Recursively removes the specified folder and everything contained inside it (including other folders).