In unix, files are organized into directories.
A directory is a collection of files and possibly subdirectories.
In unix, the hierarchy is represented with several special characters "/", "~", ".", "..".
/ is the directory separator - e.g. "/usr/bin" is the top level (root) directory "/", subdirectory usr, subdirectory "bin"
"~" is a shortcut name for your home directory
"." is a shorthand name for the directory that you are currently in (you can find out what directory you are in with "pwd" - print working directory)
".." is shorthand for referring to the directory above the one you are currently in.
All unix files and directories have permissions associated with them.
% ls -l
drwxr-x--- 2 b5chin cse250 4096 Jan 19 16:28 tmp
this is a directory called "tmp". the "d" means directory. The next group of 3 letters are the permissions for the owner. "r" mean readable, "w" means writeable, and "x" means executable. A directory must be executable in order for you to change into it.
The next 3 positions represent the read, write and execute permissions for the group. In this case the group is cse260 and the directory tmp is readable and executable by the group but not writeable. All unix users have a user name and one or more group memberships. In this case, if a user is a member of the group cse260 they could access this directory.
The last 3 positions represent the read, write and execute permissions for every else (called "other").
Files have a similar permission structure:
% ls -l Makefile
-rw------- 1 b5chin cse260-staff 2008 Jan 10 20:32 Makefile
Notice, this is a file and not a directory so there is no "d" in the first character potion
Directories can be created with the command
mkdir directoryname
Directories (if empty) can be removed with
rmdir directoryname
Directories can be moved (renamed) with
mv oldname newname
To search for strings in a file you can use grep
ex: ls -la | grep -i "blocking"
diff filename1 filename2 compares files, and shows where they differ
wc filename tells you how many lines, words, and characters there are in a file
chmod options filename can be used to change the read/write/execute permission on a file
chmod o+r filename will make it readable to everyone and chmod o-r filename will make it unreadable to everyone
The main parts of the chmod permissions: Example: drwxrwx---
To the right of the "d":
the left three characters rwx define permissions of the OWNER.
the middle three characters rwx define permissions of the GROUP.
the right three characters --- define permissions of EVERYONE ELSE.
To change the permission numerical representation can be used. 4 stands for read, 2 stands for write, 1 stands for execute and 0 stands for no permission. So 7 is the combination of permissions 4+2+1 (read, write, and execute), 5 is 4+0+1(read, no write, and execute), and 4 is 4+0+0 (read, no write, and no execute).
example: chmod 754 filename means the owner gets r/w/ex, the group gets r/ex and everyone-else gets ex
chgrp option filename is used to change the group of a file.
chgrp staff file.txt will change the owning group of file.txt to staff
chgrp -hR staff /pa1/files will change the owning group of /pa1/files, and all subdirectories, to the group staff.
To copy files from local-host to remote-host machine and vice versa use the scp (secure-copy) command
Copying file to host:
scp SourceFile user@host:directory/TargetFile
Copying file from host:
scp user@host:directory/SourceFile TargetFile
scp -r user@host:directory/SourceFolder TargetFolder
man command-name shows you the manual page for the command
For more help: http://man7.org/linux/man-pages/dir_section_1.html