Some Unix Commands
Accessing Rucs
- Use a putty (or ssh) session from a windows machine
- Directory
/home/userid is your H: drive
- On Linux/Unix, names of files, folders, and commands are case sensitive
- Using
submit: submit command must be executed on rucs and
the file must be on H: drive
Most Important Unix Commands and Information
- Your Current Directory
- Commands refer to your current directory
- Your H: Drive is your current directory when you login
- Information on your Current Directory and its Files
-
pwd - shows the name of the current directory
-
ls - list all files on current directory
-
ls -l - list all files in long format
- Examples:
-
ls foo.adb - list file foo.adb
-
ls -l foo* - long listing of all file whose name starts with
foo
- Change current directories (ie navigate among folders)
-
cd - change current directory
- Examples:
-
cd mydir - changes current directory to mydir, a subdirectory of the current directory
-
cd adir/someDir - changes current directory to
someDir, a subdirectory of directory adir which
is in the current directory
-
cd .. - changes to parent of current directory
-
cd ../someDir - changes to someDir,
a subdirectory of the parent
of the current directory (ie a sibling directory)
-
cd ~/someDir - changes to
somedir, a subdirectory of the home directory (ie H: drive)
- View file contents:
-
cat afile - view contents of file afile (concatenate)
-
less afile - view contents of afile a screen at a time
- Copy, rename, move, delate files:
-
cp f1 f2 - copy file f1
-
cp aFile newFile - create newFile, a copy of
existing file aFile
-
cp aFile someDir - copy existing file aFile into folder someDir, with name aFile
-
cp aFile someDir/someName - copy existing file
aFile into folder someDir,
with name someName
-
mv oldFile newFile -
rename (move) file oldFile to newFile
-
mv aFile someDir - move existing file aFile into folder someDir
-
mv aFile someDir/someName -
move existing file aFile into folder someDir,
with name someName
-
rm theFile - delete (remove) file theFile
- Manipulate folders:
-
mkdir - make a directory
-
mkdir myDir - make a directory called
myDir in the current folder
-
rmdir myDir - remove directory myDir(must be empty)
Other Unix Commands
- 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
- View file contents:
-
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:
-
touch f1 - create f1 as an empty file
- 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