Unix/Linux commands

| | Comments (1)

12:08 PM 4/27/2005: This is my personal page for quick reference to Linux commands I generally use. I have set the date to one year back i.e. 04/27/2004 and so it should not appear in the RSS feed and annoy you! :)

- Man pages
- Unix Commands and Utilities
- Linux Basics


[1] Find a file
find . -name filename.ext
find . -name project*.* (example)


[2.1] Zip a file
gzip filename (original file is moved to filename.gz)

[2.2] Zip(tar) a directory
tar -cvf file.tar directory_name (original directory is retained)
tar -tvf file.tar (list contents)

General rule is: tar and then gzip:
tar -cvf file.tar directory_name
gzip file.tar
So, you will get a tar.gz file

[2.3] Zip(tar) a directory in 1 step
tar czvf file.tar.gz directory_name (original directory is retained)


[3] Unzip a file

[3.1] .gz file
gzip -d file.gz
(Note: original .gz file gets deleted)

[3.2] tar.gz file
gzip -d file.tar.gz
and then
tar -xvf file.tar


[4] Creating a symlink
ln -s target_path symlink_name


[5] Delete a non empty directory
\rm -fr directory_name


[6] List detailed directory listing by last modified
ls -lt


[7] Copy entire directory
mkdir target_directory
cd source_directory
cp -ap . target_directory

Other options:
cp -apv . target_directory (for verbose results)
\cp -ap . target_directory (for unix)


[8] View quota
quota -v


[9] View disk usage for current folder
du -k
du -h (uses K, M, G etc for KB, MB, GB - this is better)


[10] View space usage on disks
df -k


[11] change the file permissions of all files in a directory
chmod -R 755 docs


[12] Changing the default editor
export EDITOR=pico


[13] Edit crontab
crotab -e


[14] View uptime
uptime


[15] Restart iptables
/etc/init.d/iptables start
/etc/init.d/iptables stop
/etc/init.d/iptables restart

http://www.siliconvalleyccie.com/linux-hn/iptables-intro.htm

[16] Count number of files
find directory_name \! -type d | wc -l
Example: find /var/qmail/queue/pid \! -type d | wc -l

More at: http://www.dsl.org/cookbook/cookbook_10.html

[17] Change group
chgrp new_group filename

[18] Change owner
chown new_owner filename

[19] Find IP address
/sbin/ifconfig
Note: This gives the local ip of your machine. Look in eth0 > inet addr.

[20] Find folder size
du -sh * (this is good)
du -ah --max-depth=1
du - sc /foldername/*

[21] Start Apache
/etc/rc.d/init.d/httpd start (start)
/etc/rc.d/init.d/httpd restart (restart)
or
/sbin/service httpd start
/sbin/service httpd restart

[22] Copy entire folder from one Linux server to another using SCP
Syntax:
> scp -r source_folder user@server:destination_folder
Example:
> scp -r /home/maisnam/www maisnam@192.168.1.107:/home/maisnam/
The above example copies the www folder in /home/maisnam/ from server 1 to the /home/maisnam/ folder on server 2 (192.168.1.107 in the example above).

[22] Hard Drive Info
fdisk -l
df -h
hdparm -i device
http://www.linuxforums.org/forum/peripherals-hardware/32190-command-hard-drive-info.html
Notes: hda or sda = hard drive, sdb = secondary hard drive, sdc = thumb drive etc

[23] Linux Version
uname -a

[24] Yum GroupInstall
yum groupinstall "MySQL Server"
yum groupinstall "Web Server"
yum grouplist
http://www.cyberciti.biz/faq/rhel-yum-grouplist-groupinstall-option-not-working/

# display list of yum packages
yum list available

# install single yum package
yum install mysql

# display list of installed packages
# http://www.electrictoolbox.com/yum-list-installed-packages/
yum list installed
yum list installed | more
yum list installed | less

Categories




1 Comments

Kitawat said:

Thanks for this post

Leave a comment

About this Entry

This page contains a single entry by Bobby published on April 27, 2004 12:08 PM.

Western Digital 120 gb harddrive (WDC WD1200JBRTL) was the previous entry in this blog.

Manthan GB meeting and elections. is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

Powered by Movable Type 4.0