|
Table of Contents
|
a2enmod
Enable/disable or view modules for apache server.
acpi
Shows battery and thermal information. Try with -t for thermal.
adduser/addgroup
Add a user or group to the system
For example "adduser reza" adds user reza to the system, "addgroup admin" adds group admin to the system, "adduser reza admin" adds user reza to admin group.
Add users to the end of /etc/sudoers to give them sudo privileges. That file is so flexible for example you can add root capability to a group, etc.
See usermod.
In CentOS sudo is not installed by default and you should install it first using yum install sudo.
alias
For example alias lh="ls -l -a $HOME" makes the command "lh" become equivalent to the longer command "lh -l -a $HOME". You can use it in bash profile and assign a simple alias to a long and frequently used command.
apt
| apt-cache search clone | Searches the packages indexes for the clone name |
| apt-cache show sun-java6-bin | see info about that package |
| apt-get autoremove | removes packages that were automatically installed to satisfy dependencies for some package and that are no more needed |
| apt-get remove the-package | removes the-package |
| apt-get —purge remove gnome-panel | remove the-package with all its configuration files, etc. |
| apt-get —purge autoremove the-package | removes the-package with all its package dependencies and config files. |
| apt-get update | Updates the package indexes |
| apt-get upgrade | Installs the newest packages |
bg
Shows the last stopped command using Ctrl-Z. See fg.
cal
Display a calendar
cat
Display the contents of a file
cat file_name | grep —color some_text
chkconfig
Updates and queries runlevel information for system services.
Adding to it: chkconfig —add the_script. Notice that the_script should be chkconfig friendly. See a section in linux-how-to
chgrp
| Command | Desc |
| chgrp user file | Makes file belong to the group user |
chmod
chmod [references][operator][modes] file1 …
Reference: u (user), g (group), o (others), a (all)
Operator: +, -, =
Mode: r, w, x, X, s, t
Example:
| Command | Desc |
| chmod ug+rw sample | Adds the read and write permissions to the user and group for that file |
| chmod +x ss | Anyone can execute the file ss |
| chmod og=r archive.sh | others and group have read access |
chown
| Command | Desc |
| chown cliff file | Makes cliff the owner of file |
| chown -R cliff dir | Makes cliff the owner of dir and everything in its directory tree |
cp
Copy files and directories. To copy a dir with content use "cp -r source dest" or "cp -r * dest" copies everything in current directory to dest.
crontab
"crontab -l" show all the cron jobs for the current user.
date
Shows date and time
df
Display disk space information
env
Environment variables
export
- export shows some env stuff
- export CASROOT=/usr/local/CAS3.0 Defines the environment variable CASROOT
- export PATH=$PATH:$HOME/bin I am setting the PATH environment variable to the previous value of itself, followed by a colon, and a directory-name formed from the HOME variable and "/bin"
echo
echo $CASROOT Prints out the value of CASROOT, or /usr/local/CAS3.0
fg
Goes to the last stopped command using Ctrl-Z. See bg.
find
Searches for files by name, etc.
| Command | Desc |
| find search_path -name filename | Normal usage |
| find . -name aaa.txt | Finds all the files named 'aaa.txt' in the current directory or any subdirectory tree |
| find . -name *.sql | accepts wildcards |
| find / -name vimrc | Find all the files named 'vimrc' anywhere on the system |
| find /usr/local/games -name "*xpilot*" | Find all files whose names contain the string 'xpilot' which exist within the '/usr/local/games' directory tree |
| find / -name 'mypage.htm' | search for any file named mypage.htm on the root and all subdirectories from the root |
| find /backups/ -type f -mtime +5 -exec rm {} \; | Finds are the files in that directory older than 5 days and deletes them! |
If you get "Permission denied", do it with sudo.
You can combine find and grep. As an example: find . -name build.xml | grep java
ftp
| Command | Desc |
| ftp | goes into ftp shell |
| open | open www.xxx.com to open the remote host using port 22 |
| cd | change directory after login |
| get | get a file and copy into your local folder |
| put | upload a file into the host |
| binary or ascii | To transfer a file in binary or ascii mode. Some ftp clients go back to ascii mode when you enter an ls or dir command. To be safe, always use the binary command before getting a binary file. |
gksudo
Is a front end for sudo which sucks.
grep
Is a very powerful search tool! Can search the content of files or output of another command.
| Options | Desc | Example |
|---|---|---|
| -r | Resursive | grep -r "reza" . OR in SunOS grep searchText *.* |
| -d recurse | same as -r | |
| -n | line number | |
| —color | add color |
groupmod
modify groups.
groups
Returns the user's groups. See whoami and id.
kill
kill <PID> kills a process . if it does not work then use kill -9 <PID>
last
shows information about the last logged in users, etc
ls
| Option | Desc |
| -l | List showing date, owner,… |
| -a | Shows hiddens as well |
| -lt | List sort by time |
When you do ls -l you will get:
| type and permission | no of links | owner | group | size | date | name |
| drwxrwxrwx | 4 | reza | team | 122 | Dec 12 18:02 | xys |
lsmod
Show status of modules loaded into kernel. It resides in /sbin
lsof
List of open files and processes that opened them. It includes disk files, ports, etc.
For the ports do:
sudo /usr/local/bin/lsof -i :80
lspci
Lists all pci hardware devices connected
ln
ln -s /x/file.ext : makes a symbolic link in the current dir to /x/file.ext
mount
mount by force when you get mount errors: sudo mount -t ntfs-3g /dev/sdb1 /media/Network -o force
The better way is to connect the device, restart the system and everything should be good.
mv
Rename or move files.
netstat
Networking information
netstat -an show which ports are listening, etc.
nmap
This utility is for network exploration or security auditing.
| nmap -p 80 localhost | tells the status of port 80 |
| sudo nmap -sT -O myip | all open ports on myip |
pargs
Examines a process and prints related information such as arguments and environment variables, etc.
For example pargs<PID> is useful with ptree and ps.
ptree
Shows processes in a tree format. It is usually used as ptree <PID>.
ps
view processes
| Command | Desc |
| ps -ef | grep 'jboss4/bin' | Filters and shows (e)very process in a (f)ull list. |
reboot
"sudo reboot" reboots the system.
rm
rm removes files. To remove directories use -fr option.
scp
Remote copy: scp the_file reza@the_ip:/home/reza/. This will ask for the password in the remote machine.
shutdown
To shutdown or restart the system.
| shutdown -P now | shutdown now |
| shutdown -P +30 | shutdown in 30 min |
| shutdown -P 22:10 | shutdown at a specified time |
sudo
Run commands as another user.
sudo -u jboss x.sh runs the file as a jboss user. When used without -u then it is root.
tar
| Command | Desc |
| tar xvf archive.tar | Extract from the archive file |
| tar cvfz archive.tar.gz SOURCE | Create a gzip compressed tar archive containing everything in the directory 'SOURCE'. You can create archives with gzip,… as well. |
tail
tail -f myfile.txt -n 100 : list the last 100 lines in the file myfile.txt. and stays there to follow
top
Shows a real time view of processes, memory usage, load, CPU state, etc.
uname
Useful information about kernel, version, distribution, machine, ….
usermod
modify a user account. Can be used to rename users. If you rename a user don't forget to change these: /etc/passwd, /etc/group, /etc/shadow and home directory.
usermod -a -G root reza : adds user reza to roots users.
users
Prints the users currently logged in to the system.
view
view filename = vi or vim
vi commands
| Command | Desc |
|---|---|
| i | Enter text entry mode (Esc to exit) |
| ZZ | Write (if there were changes), then quit |
| :wq | Write, then quit |
| :q | Quit (will only work if file has not been changed) |
| :q! | Quit without saving changes to file |
| x | Delete a character (in command mode) |
| dd | Delete a line (in command mode) |
| Esc | leave insert (text entry) mode and return to command mode |
| yy | Copy (yank) the current line |
| R | Overwrite text, press <Esc> to end |
| 6yy | Copy (yank) six lines, beginning with the current line |
| yw | Copy the current word |
| p | Put the text after the cursor position |
| P | Put the text before the cursor position |
| /text | Search forward (down) for text. Can be used when we have / in the search text! Press n or shift+n for next and previous. |
| ?text | Search backward (up) for text |
| :set nu | Display line numbers |
| :set nonu | Hide line numbers |
| gg | Goto start of the file |
| G | Goto end of the file |
which
Shows the physical location of a command for example "which ls" tell where the "ls" is located in the disk.
yum install wget
yum update
yum
yum - Yellowdog Updater Modified, is the equivalent of apt-get for RH/CentOS.
Key combinations
- Ctrl-C: Usually sends the kill signal, which terminates a process.
- Ctrl-Z: Sends the stop signal, which stops process execution immediately, without terminating. Use “fg” or “bg” after that.
- Ctrl-L: Clears the screen and works like clear command.
who
shows who is logged in.
xev
Shows a window (in X server) and sends all X server events to it. It is good for debugging keys, mouse, etc.
Other References
File Access and Permissions
There are three types of access:
- read (r)
- write (w)
- execute (x)
There are three types of files:
- ordinary file (-)
- directory (d)
- link (l)
When a file listing (ls) is done, there are 10 characters that are shown on the left that indicate type and permissions of the file:
-rw-r--r-- 1 jboss jboss 2481 Feb 25 12:43 run.conf
- The first character indicates the type of file
- The next three indicate read, write, and execute permission for user, group and other.
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 |
| File Type | user r | user w | user x | group r | group w | group x | others r | others w | others x |





