Linux Commands :
Most of you will be using X-Windows and various GUI tools or possibly even
Webmin. What follows are some very basic
commands for manipulating files. There are much better resources out on the web
than this. See the man pages for each command for more information as well. Create, Copy, & Delete
cp [from] [to]
Copy files/directories from one location to another.
mv [from] [to]
Move files/directories from one location to another. Can also be used for renaming.
rm [options] [file]
Remove files/directories. Wildcards supported for [file].
mkdir [name]
Create a directory.
rmdir [name]
Remove a directory.
touch [name]
Creates the [name] if it does not exist or updates the time stamp.
Display
ls [options]
List files/directories. Commonly used options:
-l = full information
-a = show files who's name begins with . (aka hidden files)
find dir_to_start_in -name file_to_find -print
Seach for a file. Wildcards accepted.
pwd
Print the current directory path you are in.
df [options]
Show space available on disk. Without options shows for all mounted file systems
du
Show space used by current directory and sub-directories.
Modify Attributes
chown [name] [file]
Change the owner of the files/directories. Wildcards supported for [file].
chgrp [name] [file]
Change the group of the files/directories. Wildcards supported for [file].
chmod [permissions] [dir_or_file]
Change the access permissions of the files/directories. Wildcards supported for [dir_or_file].
A few common values for [permissions]:
777 = owner [rwx] group [rwx] world [rwx]
775 = owner [rwx] group [rwx] world [r-x]
"Sticky-bits":
0### = clear all sticky-bits
1### = only owner of file can do things to it
2### = group that "owns" directory will be assigned to all files created inside
4### =
This may give you more information.
Environment Variables
printenv
Show all environment variables
export [variable]="[value]"
Set an environment variable
unset [variable]
Remove a variable
Misc
ln [options] [target] [linkname]
Makes links to selected [target]s. Default is hard links. Typically you use -s, an option, for symbolic links.
rpm [do what] [options] [file]
Use RH's package manager to install, upgrade, or remove packages. Wildcards supported for [file].
Install = rpm -ivh [file]
Upgrade or install if not exist = rpm -Uvh [file]
Upgrade but don't install if not exist = rpm -Fvh [file]
Query = rpm -q [package name] (ex: rpm -q sendmail)
Query with grep = rpm -qa | grep [name]
Information = rpm -qi [package name]
Remove = rpm -e [package]
For options you can use, in most cases:
--nodep: ignore dependencies
--replacefiles: replace conflicting files
e2fsck [options] [device]
Check and/or repair the file system. Use e2fsck --help for a full list of options.
mke2fs [options] [device]
Create a file system on a partion (aka format).
Example - check for bad blocks, ext3, 1% reserved, label:
mke2fs -c -j -m1 -L [label] /dev/hdxx
diff [options] original changed >patch_file
Make a patch of changed (a) file(s). Example:
diff -u3 -r file.c.orig file.c >file.patch
free
Display memory usage.
tar
A directory and sub directories & compress it:
With the directory name while you are in the parent:
tar clf - ./dir_name | compress > name.tar.Z
To list the contents of the resulting file:
zcat name.tar.Z | tar tvf - | more
top
Display process information real-time. Use h for help and q to quit.
Check the traffic:
/usr/sbin/tcpdump –n arp –I eth0
SSH:
Ssh –l username
<ip of machine>
Transfer files between two linux machines:
Scp <file
name> <usrname>@<ip of
machine where to send the file>:/<path to send the file>
******[To transfer a directory we have to zip it and then
use scp command]*****
*** how to tar and zip a dir?
Eg: cd /tmp
Mkdir testdir
Tar –cvf testdir.tar testdir
Bzip2 testdir
testdir.tar
***To unzip and untar a dir:
Bunzip2 testdir.tar
Tar –xvf testdir.tar
To automatically compress the tar file add z flag:
Eg: Tar cvzf testdir.tar.gz
FTP:
ftp <ip add of machine>
>ha
>bi
>mget <file name>
>bye *******-to
exit*****
To check the user ‘s process:
Ps –u <username>
Cat /proc/partitions
Cat /proc/version
/usr/sbin/system-config-network
/usr/sbin/system-config-nfs
env
cat /proc/swaps
rm –rf <dir
name> ****This command is used to
delete a directory which is not empty***
mozilla &
*****to open a browser*****
ps -aux | grep portmap *****to check portmap status******
dmesg
· What
daemon is responsible for tracking events on your system?
syslogd
The syslogd daemon is responsible for tracking system information and saving it to specified log files.
syslogd
The syslogd daemon is responsible for tracking system information and saving it to specified log files.
Echo $SHELL