Some Unix Commands
Accessing Rucs
- Use a putty (or ssh) session from a windows machine
- Directory
/home/userid is your H: drive
- Remember: Unix/Linux is Case Sensitive!
- Using
submit: submit command must be executed on rucs and
the file must be on H: drive
Some Example Unix Commands
- Query file information:
- Relative and Absolute Paths
- Absolute Paths: Begin with / or ~
- Relative Paths: Begin with directory or file name or . or ..
-
~ - your home (ie H:) directory
-
. - the current directory
-
.. - the parent of the current directory
- Navigate among directories (ie among folders)
- View file contents:
-
cat f1 - view contents of file f1 (concatenate)
-
less f1 - view contents of f1 a screen at a time
-
more f1 - less powerful version of less
-
head f1 - see beginning of f1
-
tail f1 - see end of f1
-
diff f1 f2 - difference between files or directories f1 and f2
- Manipulate files:
-
cp f1 f2 - create copy of f1 either named f2 (if no directory f2
exists) or in directory f2 (if directory f2 exists)
-
mv f1 f2 - rename (move) file f1 to f2
-
rm f1 - delete (remove) file f1
-
touch f1 - create f1 as an empty file
- Manipulate folders:
-
mkdir - make a directory
-
rmdir - remove a directory (must be empty)
- Help:
-
man com - help on command com
- Words in files:
-
wc f1 - word count of file f1
-
grep s f1 - search for string s in file f1
- Path and Environment:
-
which/whereis - What is executed
-
echo $path -
-
printenv - Environment variables
- Other:
- Redirection and pipe:
-
| - pipe
-
< - redirect in
-
> - redirect out
-
>> - redirect out and concatenate
Command: ls
- List files
- Examples:
-
ls - list names of files in current directory
-
ls -l - list long format (ie name, size, date, protection) of files in current directory
-
ls *.adb - list any file that has ".adb" as an extension
-
ls -l *.adb - list in long format any file that has ".adb" as an extension
-
ls -l ../*.adb - do the same in the parent directory
-
ls -l ~/*.adb - do the same in the home directory (ie h: drive)
- Options:
- ls -l - long format
- ls -a - all files
- ls -f - all files
- ls -F - mark directories and executables
- Similar windows command: dir
Absolute and Relative Path Names
- Absolute Paths: Begin with / or ~
- Relative Paths: Begin with directory or file name or . or ..
-
~ - your home (ie H:) directory
-
. - the current directory
-
.. - the parent of the current directory
- Example:
ls -l proj1/g1.adb
Command: cd
-
cd dir - Change to directory dir
- Example:
cd proj1
cd ..
cd proj2
cd ../proj3
Similar windows command: cd
Command: cat
- Concatenate files
-
cat foo.adb - displays contents of foo.adb
- Similar windows command: type
Commands: less, more
- display a file, one screen at a time
-
less foo.adb - displays contents of foo.adb
- Use spacebar to progress, ^-b to go backwards, q to quit
- more - Similar to less, but more restricted (original version called more, newer
cleverly called less)
Commands: head, tail
- head f1: display the first few lines of file f1
- tail f1: display the last few lines of file f1
Commands: diff
- diff f1 f2: display the difference between files f1 and f2
- diff f1 f2: display the difference between directories f1 and f2
Command: cp
- copy one file to another or to a directory
-
cp foo.adb foo2.adb - creates foo2.adb as a copy of
foo.adb
-
cp proj1/foo.adb submitted - creates foo.adb as a copy of
foo.adb in directory submitted
- cp ~/foo.adb . - copies foo.adb from the home directory to the current directory
- cp ~/foo.adb ./foo2.adb - copies foo.adb from the home directory to
the current directory and gives it a new name (in the current directory)
- cp ~/320/proj1/* dummy - copies all regular files (not directories) from directory
proj1 to existing directory dummy
Command: mv
- move a file (or rename it)
- mv foo.adb foo2.adb - changes name of file foo.adb to foo2.adb
- mv ~/foo.adb . - moves foo.adb from the home directory to the current directory
- cp ~/foo.adb ./foo2.adb - moves foo.adb from the home directory to
the current directory and gives it a new name
Command: rm
- remove a file
- rm foo.adb - deletes file foo.adb
- Really removes the file - does not move it to a garbage can
- Does not work on directories (unless you use -r, but CAREFUL of this
command)
- Similar Windows command: del
... More commands to come