Unix crashcourse
• unix, shell, and shellpower
Following is a list of basic shell commands for Unix:
ls
Outputs
- First column of the output is showing access rights
- rwx: read, write, executable
- Three sets of them for user, others in the group, and everyone
How do you change the access settings?
chmod u+w
will give write rights to users in the groupchmod o+x
will give executable rights to others in the groupchmod a-r
will take away read rights from all in the group
Some switches for ls
Command | Description |
---|---|
ls -a |
shows “all” files |
ls -d a* |
Wildcard to display all files whose filename begins with a |
ls -d [i-l]* |
[i-l] is a set containing letters i through l |
Cool things you can do with dot dot (..) and tilde (~)
- .. represents the parent director. So say you are in
/home/aashish
and/home
has another file calleda.java
. You can access it from aashish by saying
~/
refers to the user home directory
Using History
history
shows list of previous shell commands used. It gave following output on my computer:
- Run a certain numbered command by
!<number of the command>
. For exmaple!5676
will runjekyll serve
.
.cshrc file
~/.cshrc
contains shell configurationPATH
contains paths for programs you run on terminal. E.g. more, less etc
Random cool monitors
-
top
shows the running processes on the system -
vmstat 5
shows the paging history, 5 denotes how fast the list is being refreshed -
ps uax
shows the processes running right now
All about that stream
- Three I/O streams of unix (Similar to what it is in Java)
- Say you have a java executable called prog.class
- stdin
java prog < inputFile
will useinputFile
for keyboardinput expected by stdin in java.
- stdout
java prog > outfile
writes whateverSystem.out.println("")
into theoutfile
- Note that
System.err.println("")
is written on the screen instead of file
- Note that
java prog >& oufile
will write both stdout and stderr intooutfile
java prog > /dev/tty) >& /path
will write stdout to/dev/tty
and stderr to/path
prog >> outfile
appendas to theoutfile
instead of overwriting it
Pipe command
- Feeds the output of one command to another (prog1 to prog2). e.g.
Suspend/resume jobs aka COOL STUFF
ctrl+z
suspends/pauses the running jobbg
puts a job to backgroundjobs
prints the list of jobsfg %1
bring job no. 1 from background to foreground
grep
grep 'word' filename
searches for word in file called filenamegrep --color 'data' fileName
display grep results in colorgrep 'word' file1 file2 file3
searches for word in file1, file2 and file3grep 'string1 string2' filename
searches for string1, string2 in filenamecat otherfile | grep 'something'
pipe grep result and display its (their) contents
Tar Tricks
tar cf Simplex.tar Simplex
c
reate af
ileSimplex.tar
fromSimplex
mkdir newDir ; cd newDir ; tar xf ../Simplex.tar
- Creates
newDir
and extractsSimplex
intonewDir
- Creates
- Loop:
basename
parses out from every$i
just its filename. The loop creates a copy of every file but changes the extension to.save
.