ls
-l"?
A unix command ended with the symbol & (e.g. "emacs &") means that the unix
command will be executed in the
background. If this unix command (e.g. "emacs &") opens a x-window, then you still
can enter other unix commands in the terminal.
For example, the command "cd ~" changes the current directory to your home directory.
It is equivalent to the command "cd" or the command "cd
/home/yourusername".
For example, the command "cp ~/*.txt ." copy the all files with file extension
".txt" in your home
directory to the current directory.
For example, the command "cd .." will change the current directory to its
parent directory.
For example, the command "cd /" will change the current directory to the root directory.
The command "cd /usr/local/src/random/" will change the current directory to the
directory "/usr/local/src/random/".
Use the command "ls -ld directoryname". For example
[webmaste@pascal : unix]$ ls -ld
drwxr-xr-x 2 webmaste man 512 Apr 12 14:19 .
[webmaste@pascal : unix]$ ls -ld ../unix
drwxr-xr-x 2 webmaste man 512 Apr 12 14:19 ../unix
Without using the flag "d", we get (for the above example):
[webmaste@pascal : unix]$ ls -l
total 46
-rw-r--r-- 1 webmaste man 12867 Apr 12 00:27 commands.html
-rw-r--r-- 1 webmaste man 12867 Apr 12 00:29 commands.html.bak
-rw-r--r-- 1 webmaste man 10622 Apr 12 14:23 index.html
-rw-r--r-- 1 webmaste man 8259 Apr 12 00:29 index.html.bak
[webmaste@pascal : unix]$ ls -l ../unix
total 46
-rw-r--r-- 1 webmaste man 12867 Apr 12 00:27 commands.html
-rw-r--r-- 1 webmaste man 12867 Apr 12 00:29 commands.html.bak
-rw-r--r-- 1 webmaste man 10622 Apr 12 14:23 index.html
-rw-r--r-- 1 webmaste man 8259 Apr 12 00:29 index.html.bak
ls
-l"?
These characters indicate the permission of the file, directory, or link. Unix is a multi-user system. The user can decide to what extent other users can access his/her files. For example,
drwxr-xr-x 2 webmaste man 512 Apr 12 14:19 .
The string "drwxr-xr-x" consists of 10 characters. Generally, the format
of the access permission looks like:
If the item is file, the meaning of read, write, and execute permission is given below:
ls", "cp", and
"cat". The text editors
(such as gvim and emacs) can also open this file. However this file cannot be
saved as the same name.ls". For example, you have a shell
script "myed" which contains the following lines:
if [ $# -gt 0 ];
then
gvim $1;
cp -f $1 "$1.bak";
else
echo "Usage: myed filename"
fi
Also suppose you have the execute permission to the script. Then you can type
myed abc.txtto edit the file abc.txt by using editor gvim. Once you exit from gvim, the file abc.txt will be backup as abc.txt.bak.
If the item is directory, the meaning of read, write, and execute permission is given below:
ls".cd" to move to subdirectories of this
directory.
Note: if you are granted only x permission to a directory, abc say, but no r
permission, then you can not check the content of the directory abc by using the
command "ls". However you can use the command "cd" to move
into the directory abc, or use the command "cp" to copy files
from the directory abc.
Similarly, if you are granted only r permission to a
directory abc, but no x
permission, then you can not move into or copy files from the directory abc. However, you
check the content of the directory abc by using the
command "ls".
You can modify the permissions of your own files or directories by using the unix command
"chmod".
Suppose that you login to hajek from your home. And x-windows such as gvim, emacs, Netscape or ghostview etc. can not be displayed.
xhost + www.stat.ubc.ca
in the Unix or Linux installed at your computer.
export DISPLAY=142.103.121.1:0.0
where 142.103.121.1 is the IP address of hajek.
You can get it by typing the following command at your computer:
ping www.stat.ubc.ca
Click open to connect.
(This entry is provided by Mark Robinson in Informal Computing Seminar - January 20, 2000.)
# Using_at_.txt # Informal Computing Seminar - January 20, 2000 at can be used to schedule the running of some "job" at some pre-specified time. A possible use of this is to run an Splus job (or a C program) in the middle of the night to reduce the drain on HAJEK during the day. Some Examples are given below: 1. The following will send me an email (with the subject "hello") 1 minute from now with a listing of the current directory (i.e. the directory from which this command is invoked). at now +1 min < mailscript (break this down ... look at what is in the mailscript file .... ls -la gives a long listing of the files in the current directory ... the output of this command is "piped" into the mailx command which will send the email to mark ... the at command schedules this to run 1 min after it is evoked from the prompt. NOTES: *in the place of min you can use day, month, year, hour. *at -l will list all current jobs and ids *at -r <job-id> will delete a job *calling your job with at -m <..stuff..> will send you an email after completion. 2. To run an Splus job today at 5:00 pm, one could use the following: at 0500pm jan 20 < atdemoscript (break this down ... here we "pipe" IN the file atdemoscript ... this will run whatever is in the file atdemoscript -- just as if it were typed at the prompt -- so therefore "cat atdemo.s | Splus > temp.out" (contents of atdemoscript) will be run at the specified time ... Note: cat atdemo.s | Splus > temp.out is one way to run Splus commands from the prompt ... the breakdown is: it takes the contents of atdemo.s and pipes it into Splus ... Splus runs whatever it has to and dumps the output into the file temp.out) 3. What does this one do? A bonus question! (a cinnamon bun to the first person to answer correctly ... be precise ... email the answer to me) at now +1 hour < mailscript1 (A related tool to this is the crontab, in which you can schedule things on a regular basis ... e.g. cleaning up core files once a month, emailing reminders of meetings, etc. ... see the man pages for info on this)
Sometimes the unix file names contain special characters. You can use "\" before these special characters to change them back to ordinary characters. For example:
rm \#abc.txt\#
mv abc\ def.txt abcdef.txt
rm abc\\def.txt
You also can use Midnight Commander to manipulate (rename, edit, copy, delete, etc. ) these files.
There are at least two ways to get online help about a Unix command. For
example, you want to know the usage of the Unix command "grep".
Then you can use the following two ways.
grep --help"grep"man grep"grep"
The file ".bashrc" is a special fie in Unix. If the Unix system uses Bash
shell, then the file ".bashrc" will be executed each time you login to
the Unix system.
In the file ".bashrc", you define environment and local variables so that
they are initialized at every login, and everytime a new shell would get created.
Usually, you don't need to change the content of .bashrc. However, sometimes you want to create alias to save time to type long commands, or you may want to add searching paths to PATH environment variable.
The syntax to define an alias is
alias alias name = 'Unix command'
For example,
# anything after the symbol # in .bashrc are comments alias rm='rm -i' alias cp='cp -i' alias mv='mv -i' alias p='cd -' #go to last directory entered alias utar='tar xvfz' #unzip and utar *.tar.gz file alias ttar='tar tvfz' #list the content of *.tar.gz files alias ctar='tar cvfz' #unzip and utar *.tar.gz file alias llm='ls -la | more' alias lls='ls -l' alias lla='ls -a' # delete temporary files created by latex alias del='rm -f *.aux *.log *.dvi *.bbl *.blg *.toc *.lof *.lot' alias s='Splus6 -e' # set font for gvim alias gvim='gvim -fn 8x13'
The syntax to define a environment variable is
Variable name="value"
For example,
SAMPLE="hello world"
To refer to an environment variable, use syntax
$variable name
For example, type in terminal
echo $SAMPLEwill produce the string hello world.
To view the values of all environment variables, type in terminal
env
In the file .bashrc, you need to use export command to activate the environment variables you defined. For example,
export EDITOR="/usr/local/bin/vim" export S_CLEDITOR="/usr/local/bin/vim" export VISUAL="/usr/local/bin/vim" export PATH=$PATH:.: export PS1="[\u@\h : \W]\\$ "
The first three export commands specify vim as the internal editor of Splus. The fourth export add "current directory" into the searching path. For example, if you create a executable file, abc say, in a subdirectory, tmp say, then you can directly type
abcto execute the file. However, if you did not export the "current directory" in the searching path, you have to type
./abcto execute the file.
The last export command in the above example change the default terminal prompt ($) to the form
[username@hostname : current directory name]$
Once you modify the .bashrc file, you can use the command source to make it effective.
source .bashrc
You can use the command pr with flag "-n". For example,
pr -n abc.txt | more
To print the file abc.txt with line number, type
pr -n abc.txt | lpr -Plj4
If you also want double space output, type
pr -n -d abc.txt | lpr -Plj4where the flag "
-d" means "double space".
You can use the command find to search a file. For example,
find $HOME -name "abc*.txt" -print
will print out information (path) of all files in your home directory and its subdirectories,
whose names begin with "abc" and end with ".txt".
The command
find $HOME -size +10k -name "abc*.txt" -print
will print out information (path) of all files in your home directory and its subdirectories,
whose names begin with "abc" and end with ".txt" and whose file sizes are
greater than 10k.
The command
find $HOME -name "core" -exec rm -f {} \;
will delete all files in your home directory and its subdirectories, whose names are core.
The flag "-exec" tells the system to execute the command after the flag
"-exec" ("rm -f {} \;")
when the command find finds the files you want to search.
By default, the standard input is the keyboard and the standard output is the monitor. However you can redirect the standard input and/or standard output to files. For example,
ls > tmp.txt
will redirect the output to the file tmp.txt.
The following command
pr < abc.txt >def.txt
is equivalent to the command
cp abc.txt def.txt
The following command concatenates the files file1.txt and file2.txt to the file file3.txt.
cat file1.txt file2.txt > file3.txt
The operator ">" will erase the original content of the file
file3.txt. If you want to append the files file1.txt and file2.txt to the file
file3.txt, use the operator ">>".
cat file1.txt file2.txt >> file3.txt
Sometimes, we want to use the output of a command as the input of another command. The unix
pipe operator "|" can do this. For example, the command
ls -l | more
means that the output of the command "ls -l" will be sent through the
pipe to the command more. The command more will accept the output as input.
Note that you need to make sure that the command on the left side of the pipe
"|" can produce outputs and the command on the right side of the pipe
can accept inputs.
The regular expression provides a grammar to define "patterns" so that unix utilities and editors can use these defined patterns to search and/or replace the same patterns in files. For example, "abc123" is a regular expression.
The unix command
grep 'abc123' test.txt
output each line of the file test.txt which contains the pattern "abc123".
In Vi, you can use the command:
/abc123
to search the pattern "abc123" in the file.
Regular expression is simple but flexible and powerful. It is a sequence of characters and consists of ordinary characters (e.g. 'a', '8') and special characters (e.g. '.', '\'). Special characters are also called operators.
The following table lists commonly used operators.
| Operator | Description |
|---|---|
| . | The period "." matches any character
except NEWLINE. For example, the regular expression "a.c" stands for strings which
begin with 'a' and end with 'c'. The strings "abc" and
"a c" both match the
pattern "a.c" . However, the string "abdc" does not match.
The string "abdc" can match the regular expression
"a..c".
|
| \ | The backslash "\" turns off the special
meaning of a special character. It is also called Escape character. For example,
the regular expression "a\.c" is different from the regular expression
"a.c". Only the string "a.c" can match the
regular expression "a\.c". |
| ^ | The symbol "^" stands for the
beginning of a line. For example, the regular expression "^a" means that
the first character of the matched string should be 'a' and that the matched string should be
the first string in the line. |
| $ | The symbol "$" stands for the
end of a line. For example, the regular expression "^a" means that
the last character of the matched string should be 'a' and that the matched string should be
the last string in the line. |
| [ ] | Any character within the square brackets can be
matched. For example, the regular expression "[aA][bB]" can be used to
search strings "ab", "aB",
"Ab", or "AB". Note that only one character in the
square bracket can be used each time. For example, the string
"aa" does not match the regular expression "[aA][bB]".
Also note that regular expression is case-sensitive.
|
| - | The symbol "-" can be used to
establish a range of characters. For example, the regular expression "[0-9]
" can be used to match any character "0",
"1", "2", ..., or "9".
The regular expression "[b-e]" can be used to match any character
"b", "c", "d", or
"e".
|
| * | The symbol "*" means that
the character immediately to its left can be repeated any times, including zero time.
The symbol "*" cannot be used as the
first character of a regular expression.
For example, the regular expression
"
The regular expression "
The regular expression "
The regular expression "
The regular expression " |
More information can be found at http://www.comp.lancs.ac.uk/computing/users/eiamjw/unix/chap10.html.
Here is the Howto. You got to play with it to make it work My example "tha" give ONLY "sysman" permission to see "newfile" chmod 711 ~tha mkdir newdir chmod 700 newdir setfacl -m user:sysman:r-x newdir setfacl -m mask:r-x newdir cd newdir vi newfile chmod 700 newfile setfacl -m user:sysman:r-- newfile setfacl -m mask:r-x newfile To check it you should run this command a) getfacl newdir and the outcome are: # file: newdir # owner: tha # group: office user::rwx user:sysman:r-x #effective:r-x group::--- #effective:--- mask:r-x other:--- Look at the #Effective for Sysman is r-x (Read and execute) b) getfacl newfile # file: newdir/newfile # owner: tha # group: office user::rw- user:sysman:r-- #effective:r-- group::--- #effective:--- mask:r-x other:--- Sysman has Read-Only to newfile
history | grep emacs
To see what files you edited with Emacs recently.
[root@dragon brenda]# ls -l /var/log/messages
-rw------- 1 root root 5490 Jun 24 09:20 /var/log/messages
[root@dragon brenda]# cp !$ !$.020624
cp /var/log/messages /var/log/messages.020624
On the second command you use "!$" instead of
typing "/var/log/messages "
# lpe -Pspit phdthesis.reviewed.ps
< some error message from bash >
# ^lpe^lpr
< file is printed >