Linux / UNIX Basics
August 27, 2010Login:
login: <user account>
password: <user password>
Logout:
logout
exit
Ctrl-D
File Systems:
pwd: print current working directory
ls [-l] [-a]: List the contents of current directory
File attributes:
drwxr-xr-x 2 root root 1024 Jun 4 17:01 bin/
- d: [-dlsbc] -> [file,directory,link,special,block,char]
- permission modes:
- user (owner) read
- group write
- others execute
- Change permission mode of files or directories:
- chmod <mode> <filenames>
- <mode>: [ugo][+-][rwx] or an octal number
- Change owner of files
- chown <user>.<group> <filenames>
Linux system directories:
/ root directory
/bin binary files
/dev device files
/etc configuration files and initialization scripts
/home root of user home directories
/lib programming language library
/lost+found lost files
/proc Linux system information
/root root home directory
/sbin binary files for system management
/tmp temporary directory
/usr user files
/var various files
/mnt a temporary mount point
Special directories:
~ : home directory
~<user> : home directory of <user>
. : current directory
.. : parent directory
Directory-related commands:
cd <directory> : change directory
mkdir <directory> : make directory
rmdir <directory> : remove directory
File-related commands:
cp <filename> <destination> : copy files
mv <filename> <destination> : move or rename files
rm <filename> : remove files
more <filename> : display file by page
cat <filename> : display the whole file
ln [-s] <oldname> <newname> : make links to files
I/O redirection:
< : input
> : output
| : pipe
Online manual pages:
man <command>: display manual page for <command>
User Info
User information commands:
who : display who is logged in on the system
w : display who is logged in, and what are they doing
whoami : display current user name
finger <user> : display information about <user>
Changing user information:
passwd : change password
chsh : change shell
chfn &nb
sp; &
nbsp;
: change finger information
Process & Job Control
Terminating processes or jobs:
Ctrl-C: interrupt current process
Ctrl-D: terminate file input
Ctrl-Z: suspend current process
Process-related commands:
ps [-x] [-a]: display information of processes
kill -9 <PID>
Job control:
<command> & : run command in background
bg : put current suspended job into background running
fg : continue suspended job
jobs : list background jobs
Alias:
alias <name> = <command line> : assign command line to the alias
unalias <name> : remove alias
File Editors: joe, vi, ed, emacs, pico, …
- Basic operation of joe:
Ctrl-KX: save file and quit
Ctrl-C: quit
Ctrl-KB: mark beginning
Ctrl-KK: mark End
Ctrl-KC: copy marked text
Ctrl-KM: move marked text
· Basic operation of vi:
(1) In command mode:
arrow keys change cursor position
i insert (change into editing mode)
a append after cursor (change into editing mode)
x delete this character
dd delete this line
:w write to file
:q quit
:q! quit without saving changes
(2) In editing mode:
ESC change back to command mode
Printing commands:
lpr <file> : print a file
lpq : list printer queue
lprm [-] : remove a printing job
Miscellaneous commands:
clear : clear screen
date : display current date and time
which <command> : display the pathname of <command>
Environment variables:
set : display current environment variables
echo $PATH : display current setting of PATH
<name>=<value>; export <name> : define a variable <name>
Shell scripts ó batch files in DOS
Local Configuration Files:
~/.cshrc : C Shell rc file
~/.login : Login scripts
~/.plan : personal plan à for finger
~/.forward : e-mail forward list
Becoming superuser:
su <root>
sudo <command>
Useful tools:
find <dir> [-name <filename>] [-print] : find <filename> from <dir>
grep <string> <files> : search <string> in <files>
diff <file1> <file2> : display the differences between <file1> and <file2>