แสดงบทความที่มีป้ายกำกับ linux แสดงบทความทั้งหมด
แสดงบทความที่มีป้ายกำกับ linux แสดงบทความทั้งหมด

25540802

linux-command

This is a linux command line reference for common operations.

Examples marked with • are valid/safe to paste without modification into a terminal, so

you may want to keep a terminal window open while reading this so you can cut & paste.


All these commands have been tested both on Fedora and Ubuntu.

See also more linux commands.


http://www.pixelbeat.org/cmdline.html




































































































































































































































































































CommandDescription
•apropos whatisShow commands pertinent to string. See also threadsafe
•man -t ascii | ps2pdf - > ascii.pdfmake a pdf of a manual page
which commandShow full path name of command
time commandSee how long a command takes
•time catStart stopwatch. Ctrl-d to stop. See also sw
dir navigation
•cd -Go to previous directory
•cdGo to $HOME directory
(cd dir && command)Go to dir, execute command and return to current dir
•pushd .Put current dir on stack so you can popd back to it
•alias l='ls -l --color=auto'quick dir listing
•ls -lrtList files by date. See also newest and find_mm_yyyy
•ls /usr/bin | pr -T9 -W$COLUMNSPrint in 9 columns to width of terminal
find -name '*.[ch]' | xargs grep -E 'expr'Search 'expr' in this dir and below. See also findrepo
find -type f -print0 | xargs -r0 grep -F 'example'Search all regular files for 'example' in this dir and below
find -maxdepth 1 -type f | xargs grep -F 'example'Search all regular files for 'example' in this dir
find -maxdepth 1 -type d | while read dir; do echo $dir; echo cmd2; doneProcess each item with multiple commands (in while loop)
•find -type f ! -perm -444Find files not readable by all (useful for web site)
•find -type d ! -perm -111Find dirs not accessible by all (useful for web site)
•locate -r 'file[^/]*\.txt'Search cached index for names. This re is like glob *file*.txt
•look referenceQuickly search (sorted) dictionary for prefix
•grep --color reference /usr/share/dict/wordsHighlight occurances of regular expression in dictionary
archives and compression
gpg -c fileEncrypt file
gpg file.gpgDecrypt file
tar -c dir/ | bzip2 > dir.tar.bz2Make compressed archive of dir/
bzip2 -dc dir.tar.bz2 | tar -xExtract archive (use gzip instead of bzip2 for tar.gz files)
tar -c dir/ | gzip | gpg -c | ssh user@remote 'dd of=dir.tar.gz.gpg'Make encrypted archive of dir/ on remote machine
find dir/ -name '*.txt' | tar -c --files-from=- | bzip2 > dir_txt.tar.bz2Make archive of subset of dir/ and below
find dir/ -name '*.txt' | xargs cp -a --target-directory=dir_txt/ --parentsMake copy of subset of dir/ and below
( tar -c /dir/to/copy ) | ( cd /where/to/ && tar -x -p )Copy (with permissions) copy/ dir to /where/to/ dir
( cd /dir/to/copy && tar -c . ) | ( cd /where/to/ && tar -x -p )Copy (with permissions) contents of copy/ dir to /where/to/
( tar -c /dir/to/copy ) | ssh -C user@remote 'cd /where/to/ && tar -x -p' Copy (with permissions) copy/ dir to remote:/where/to/ dir
dd bs=1M if=/dev/sda | gzip | ssh user@remote 'dd of=sda.gz'Backup harddisk to remote machine
rsync (Network efficient file copier: Use the --dry-run option for testing)
rsync -P rsync://rsync.server.com/path/to/file fileOnly get diffs. Do multiple times for troublesome downloads
rsync --bwlimit=1000 fromfile tofileLocally copy with rate limit. It's like nice for I/O
rsync -az -e ssh --delete ~/public_html/ remote.com:'~/public_html'Mirror web site (using compression and encryption)
rsync -auz -e ssh remote:/dir/ . && rsync -auz -e ssh . remote:/dir/Synchronize current directory with remote one
ssh (Secure SHell)
ssh $USER@$HOST commandRun command on $HOST as $USER (default command=shell)
•ssh -f -Y $USER@$HOSTNAME xeyesRun GUI command on $HOSTNAME as $USER
scp -p -r $USER@$HOST: file dir/Copy with permissions to $USER's home directory on $HOST
scp -c arcfour $USER@$LANHOST: bigfileUse faster crypto for local LAN. This might saturate GigE
ssh -g -L 8080:localhost:80 root@$HOSTForward connections to $HOSTNAME:8080 out to $HOST:80
ssh -R 1434:imap:143 root@$HOSTForward connections from $HOST:1434 in to imap:143
ssh-copy-id $USER@$HOST Install public key for $USER@$HOST for password-less log in
wget (multi purpose download tool)
•(cd dir/ && wget -nd -pHEKk http://www.pixelbeat.org/cmdline.html)Store local browsable version of a page to the current dir
wget -c http://www.example.com/large.fileContinue downloading a partially downloaded file
wget -r -nd -np -l1 -A '*.jpg' http://www.example.com/dir/Download a set of files to the current directory
wget ftp://remote/file[1-9].iso/FTP supports globbing directly
•wget -q -O- http://www.pixelbeat.org/timeline.html | grep 'a href' | headProcess output directly
echo 'wget url' | at 01:00Download url at 1AM to current dir
wget --limit-rate=20k urlDo a low priority download (limit to 20KB/s in this case)
wget -nv --spider --force-html -i bookmarks.htmlCheck links in a file
wget --mirror http://www.example.com/Efficiently update a local copy of a site (handy from cron)
networking (Note ifconfig, route, mii-tool, nslookup commands are obsolete)
ethtool eth0Show status of ethernet interface eth0
ethtool --change eth0 autoneg off speed 100 duplex fullManually set ethernet interface speed
iwconfig eth1Show status of wireless interface eth1
iwconfig eth1 rate 1Mb/s fixedManually set wireless interface speed
•iwlist scanList wireless networks in range
•ip link showList network interfaces
ip link set dev eth0 name wanRename interface eth0 to wan
ip link set dev eth0 upBring interface eth0 up (or down)
•ip addr showList addresses for interfaces
ip addr add 1.2.3.4/24 brd + dev eth0Add (or del) ip and mask (255.255.255.0)
•ip route showList routing table
ip route add default via 1.2.3.254Set default gateway to 1.2.3.254
•host pixelbeat.orgLookup DNS ip address for name or vice versa
•hostname -iLookup local ip address (equivalent to host `hostname`)
•whois pixelbeat.orgLookup whois info for hostname or ip address
•netstat -tuplList internet services on a system
•netstat -tupList active connections to/from system
windows networking (Note samba is the package that provides all this windows specific networking support)
•smbtreeFind windows machines. See also findsmb
nmblookup -A 1.2.3.4Find the windows (netbios) name associated with ip address
smbclient -L windows_boxList shares on windows machine or samba server
mount -t smbfs -o fmask=666,guest //windows_box/share /mnt/shareMount a windows share
echo 'message' | smbclient -M windows_boxSend popup to windows machine (off by default in XP sp2)
text manipulation (Note sed uses stdin and stdout. Newer versions support inplace editing with the -i option)
sed 's/string1/string2/g'Replace string1 with string2
sed 's/\(.*\)1/\12/g'Modify anystring1 to anystring2
sed '/ *#/d; /^ *$/d'Remove comments and blank lines
sed ':a; /\\$/N; s/\\\n//; ta'Concatenate lines with trailing \
sed 's/[ \t]*$//'Remove trailing spaces from lines
sed 's/\([`"$\]\)/\\\1/g'Escape shell metacharacters active within double quotes
•seq 10 | sed "s/^/ /; s/ *\(.\{7,\}\)/\1/"Right align numbers
sed -n '1000{p;q}'Print 1000th line
sed -n '10,20p;20q'Print lines 10 to 20
sed -n 's/.*<title>\(.*\)<\/title>.*/\1/ip;T;q'Extract title from HTML web page
sed -i 42d ~/.ssh/known_hostsDelete a particular line
sort -t. -k1,1n -k2,2n -k3,3n -k4,4nSort IPV4 ip addresses
•echo 'Test' | tr '[:lower:]' '[:upper:]'Case conversion
•tr -dc '[:print:]' < /dev/urandomFilter non printable characters
•tr -s '[:blank:]' '\t' </proc/diskstats | cut -f4cut fields separated by blanks
•history | wc -lCount lines
set operations (Note you can export LANG=C for speed. Also these assume no duplicate lines within a file)
sort file1 file2 | uniqUnion of unsorted files
sort file1 file2 | uniq -dIntersection of unsorted files
sort file1 file1 file2 | uniq -uDifference of unsorted files
sort file1 file2 | uniq -uSymmetric Difference of unsorted files
join -t'\0' -a1 -a2 file1 file2Union of sorted files
join -t'\0' file1 file2Intersection of sorted files
join -t'\0' -v2 file1 file2Difference of sorted files
join -t'\0' -v1 -v2 file1 file2Symmetric Difference of sorted files
math
•echo '(1 + sqrt(5))/2' | bc -lQuick math (Calculate φ). See also bc
•seq -f '4/%g' 1 2 99999 | paste -sd-+ | bc -lCalculate π the unix way
•echo 'pad=20; min=64; (100*10^6)/((pad+min)*8)' | bcMore complex (int) e.g. This shows max FastE packet rate
•echo 'pad=20; min=64; print (100E6)/((pad+min)*8)' | pythonPython handles scientific notation
•echo 'pad=20; plot [64:1518] (100*10**6)/((pad+x)*8)' | gnuplot -persistPlot FastE packet rate vs packet size
•echo 'obase=16; ibase=10; 64206' | bcBase conversion (decimal to hexadecimal)
•echo $((0x2dec))Base conversion (hex to dec) ((shell arithmetic expansion))
•units -t '100m/9.58s' 'miles/hour'Unit conversion (metric to imperial)
•units -t '500GB' 'GiB'Unit conversion (SI to IEC prefixes)
•units -t '1 googol'Definition lookup
•seq 100 | (tr '\n' +; echo 0) | bcAdd a column of numbers. See also add and funcpy
calendar
•cal -3Display a calendar
•cal 9 1752Display a calendar for a particular month year
•date -d friWhat date is it this friday. See also day
•[ $(date -d '12:00 +1 day' +%d) = '01' ] || exitexit a script unless it's the last day of the month
•date --date='25 Dec' +%AWhat day does xmas fall on, this year
•date --date='@2147483647'Convert seconds since the epoch (1970-01-01 UTC) to date
•TZ='America/Los_Angeles' dateWhat time is it on west coast of US (use tzselect to find TZ)
•date --date='TZ="America/Los_Angeles" 09:00 next Fri'What's the local time for 9AM next Friday on west coast US
locales
•printf "%'d\n" 1234Print number with thousands grouping appropriate to locale
•BLOCK_SIZE=\'1 ls -lUse locale thousands grouping in ls. See also l
•echo "I live in `locale territory`"Extract info from locale database
•LANG=en_IE.utf8 locale int_prefixLookup locale info for specific country. See also ccodes
•locale -kc $(locale | sed -n 's/\(LC_.\{4,\}\)=.*/\1/p') | lessList fields available in locale database
recode (Obsoletes iconv, dos2unix, unix2dos)
•recode -l | lessShow available conversions (aliases on each line)
recode windows-1252.. file_to_change.txtWindows "ansi" to local charset (auto does CRLF conversion)
recode utf-8/CRLF.. file_to_change.txtWindows utf8 to local charset
recode iso-8859-15..utf8 file_to_change.txtLatin9 (western europe) to utf8
recode ../b64 < file.txt > file.b64Base64 encode
recode /qp.. < file.qp > file.txtQuoted printable decode
recode ..HTML < file.txt > file.htmlText to HTML
•recode -lf windows-1252 | grep euroLookup table of characters
•echo -n 0x80 | recode latin-9/x1..dumpShow what a code represents in latin-9 charmap
•echo -n 0x20AC | recode ucs-2/x2..latin-9/xShow latin-9 encoding
•echo -n 0x20AC | recode ucs-2/x2..utf-8/xShow utf-8 encoding
CDs
gzip < /dev/cdrom > cdrom.iso.gzSave copy of data cdrom
mkisofs -V LABEL -r dir | gzip > cdrom.iso.gzCreate cdrom image from contents of dir
mount -o loop cdrom.iso /mnt/dirMount the cdrom image at /mnt/dir (read only)
cdrecord -v dev=/dev/cdrom blank=fastClear a CDRW
gzip -dc cdrom.iso.gz | cdrecord -v dev=/dev/cdrom -Burn cdrom image (use dev=ATAPI -scanbus to confirm dev)
cdparanoia -BRip audio tracks from CD to wav files in current dir
cdrecord -v dev=/dev/cdrom -audio -pad *.wavMake audio CD from all wavs in current dir (see also cdrdao)
oggenc --tracknum='track' track.cdda.wav -o 'track.ogg'Make ogg file from wav file
disk space (See also FSlint)
•ls -lSrShow files by size, biggest last
•du -s * | sort -k1,1rn | headShow top disk users in current dir. See also dutop
•du -hs /home/* | sort -k1,1hSort paths by easy to interpret disk usage
•df -hShow free space on mounted filesystems
•df -iShow free inodes on mounted filesystems
•fdisk -lShow disks partitions sizes and types (run as root)
•rpm -q -a --qf '%10{SIZE}\t%{NAME}\n' | sort -k1,1nList all packages by installed size (Bytes) on rpm distros
•dpkg-query -W -f='${Installed-Size;10}\t${Package}\n' | sort -k1,1nList all packages by installed size (KBytes) on deb distros
•dd bs=1 seek=2TB if=/dev/null of=ext3.testCreate a large test file (taking no space). See also truncate
•> filetruncate data of file or create an empty file
monitoring/debugging
•tail -f /var/log/messagesMonitor messages in a log file
•strace -c ls >/dev/nullSummarise/profile system calls made by command
•strace -f -e open ls >/dev/nullList system calls made by command
•strace -f -e trace=write -e write=1,2 ls >/dev/nullMonitor what's written to stdout and stderr
•ltrace -f -e getenv ls >/dev/nullList library calls made by command
•lsof -p $$List paths that process id has open
•lsof ~List processes that have specified path open
•tcpdump not port 22Show network traffic except ssh. See also tcpdump_not_me
•ps -e -o pid,args --forestList processes in a hierarchy
•ps -e -o pcpu,cpu,nice,state,cputime,args --sort pcpu | sed '/^ 0.0 /d'List processes by % cpu usage
•ps -e -orss=,args= | sort -b -k1,1n | pr -TW$COLUMNSList processes by mem (KB) usage. See also ps_mem.py
•ps -C firefox-bin -L -o pid,tid,pcpu,stateList all threads for a particular process
•ps -p 1,$$ -o etime=List elapsed wall time for particular process IDs
•last rebootShow system reboot history
•free -mShow amount of (remaining) RAM (-m displays in MB)
•watch -n.1 'cat /proc/interrupts'Watch changeable data continuously
•udevadm monitorMonitor udev events to help configure rules
system information (see also sysinfo) ('#' means root access is required)
•uname -aShow kernel version and system architecture
•head -n1 /etc/issueShow name and version of distribution
•cat /proc/partitionsShow all partitions registered on the system
•grep MemTotal /proc/meminfoShow RAM total seen by the system
•grep "model name" /proc/cpuinfoShow CPU(s) info
•lspci -tvShow PCI info
•lsusb -tvShow USB info
•mount | column -tList mounted filesystems on the system (and align output)
•grep -F capacity: /proc/acpi/battery/BAT0/infoShow state of cells in laptop battery
#dmidecode -q | lessDisplay SMBIOS/DMI information
#smartctl -A /dev/sda | grep Power_On_HoursHow long has this disk (system) been powered on in total
#hdparm -i /dev/sdaShow info about disk sda
#hdparm -tT /dev/sdaDo a read speed test on disk sda
#badblocks -s /dev/sdaTest for unreadable blocks on disk sda
interactive (see also linux keyboard shortcuts)
•readlineLine editor used by bash, python, bc, gnuplot, ...
•screenVirtual terminals with detach capability, ...
•mcPowerful file manager that can browse rpm, tar, ftp, ssh, ...
•gnuplotInteractive/scriptable graphing
•linksWeb browser
•xdg-open .open a file or url with the registered desktop application



25540708

del-s

find . -name '*.txt' | xargs rm
***********************************
like del /s ------------> ind windows
http://ubuntuforums.org/showthread.php?t=371496

25540623

date1

date (Unix)
From Wikipedia, the free encyclopedia
Unix date command

The Unix date command displays the time and date. The super-user can use it to set the system clock.
Contents
[hide]

1 Usage
2 Formatting
3 Options
4 Examples
5 Setting the date
6 See also
7 External links

[edit] Usage

With no options, the date command displays the current date and time, including the abbreviated day name, abbreviated month name, day of the month, the time separated by colons, the timezone name, and the year. For example:

$date
Fri Jul 27 14:12:06 EDT 2007

Note that the implementation of the date command differs between Unix flavors. Specifically the GNU coreutils based command is much different than other POSIX implementations.
[edit] Formatting

To format a date provide a string beginning with + .
Format specifiers (format string starts with +) Specifier Description Values/Example
Day
%a weekday, abbreviated Thu
%A weekday, full Thursday
%d day of the month (dd), zero padded 23
%e day of the month (dd) 23
%j day of year, zero padded 001-366
%u day of week starting with Monday (1), i.e. mtwtfss 4
%w day of week starting with Sunday (0), i.e. smtwtfs 4
Week
%U week number Sunday as first day of week 01–53
%W week number Monday as first day of week 01–53
%V week of the year 01–53
Month
%m mm month 06
%h Mon Jun
%b Mon, locale's abbreviated Jun
%B locale's full month, variable length June
Year
%y yy two digit year 00–99
%Y ccyy year 2011
%g 2-digit year corresponding to the %V week number
%G 4-digit year corresponding to the %V week number
Century
%C cc century 00–99
Date
%D mm/dd/yy 06/23/11
%x locale's date representation (mm/dd/yy) 06/23/2011
%F %Y-%m-%d 2011-06-23
Hours
%l (Lowercase L) hour (12 hour clock) 12
%I (Uppercase I) hour (12 hour clock) zero padded 12
%k hour (24 hour clock) 12
%H hour (24 hour clock) zero padded 12
%p locale's upper case AM or PM (blank in many locales) PM
%P locale's lower case am or pm pm
Minutes
%M MM minutes 21
Seconds
%s seconds since 00:00:00 1970-01-01 UTC (Unix epoch) 1308831708
%S SS second 00–60
(The 60 is necessary to accommodate a leap second)
%N nanoseconds 000000000–999999999
Time
%r hours, minutes, seconds (12-hour clock) 12:21:48 PM
%R hours, minutes (24 hour clock) hh:mm e.g. 12:21
%T hours, minutes, seconds (24-hour clock) 12:21:48
%X locale's time representation (%H:%M:%S)
Date and Time
%c locale's date and time Sat Nov 04 12:02:33 EST 1989
Time zone
%z -zzzz RFC-822 style numeric timezone -0500
%Z time zone (e.g., EDT) nothing if no time zone is determinable EST

literals: %n newline %% percent %t horizontal tab

By default, date pads numeric fields with zeroes.

GNU date, but not BSD date, recognizes - (hyphen) do not pad the field and _ (underscore) pad the field with spaces between % and a numeric directive.

TZ Specifies the timezone, unless overridden by command line parameters. If neither is specified, the setting from /etc/localtime is used.
[edit] Options

-d, -de=string display time described by string, not now.

-e=datefile like de once for each line of datefile

-s, --set=string set time described by string

-n don't synchronize the clocks on groups of machines using the utility timed(8). By default, if timed is running, date will set the time on all of the machines in the local group. -n inhibites that.

-u Display or set the date in UTC (universal) time.

date [-u|--utc|--universal] [mmddHHMM[[cc]yy][[.SS]] The only valid option for this form specifies Coordinated Universal Time.

-u GMT ex: Sat Feb 5 14:49:42 GMT 2005

--utc, --universal Coordinated Universal Time local TZ Sat Feb 5 09:49:59 EST 2005

-ITIMESPEC, --iso-8601[=TIMESPEC] output date/time in ISO 8601 format. TIMESPEC=date for date only, hours, minutes, or seconds for date and time to the indicated precision.

--iso-8601 without TIMESPEC defaults to `date'.

-R, --rfc-822 output RFC-822 compliant date string, example: Wed, 16 Dec 2009 15:18:11 +0100

--help

The Single Unix Specification (SUS) mandates only one option: -u, where the date and time is printed as if the timezone was UTC+0. Other Unix and Unix-like systems provide extra options.
[edit] Examples

date "+%m/%d/%y"
7/4/06

date "+%Y%m%d"
20060704

To assign the time to a variable

START=`date '+%r'`
echo $START
03:06:02 PM
sleep 5
echo $START
03:06:02 PM

N.B. the variable has the time when it was assigned.

Yesterday assigned to variable

DATE=$(date -d yesterday +"%Y%m%d")
echo $DATE
20060704

To show the time in a different timezone, the TZ environment variable is read, Timezone types is found in /usr/share/zoneinfo

OLDTZ=$TZ
export TZ=GMT; echo "GMT: `date +\"%F %R (%Z)\"`"
GMT: 2008-10-31 12:30 (GMT)
export TZ=Europe/Stockholm; echo "Stockholm: `date +\"%F %R (%Z)\"`"
Stockholm: 2008-10-31 13:30 (CET)
export TZ=Asia/Kuala_Lumpur; echo "Kuala Lumpur: `date +\"%F %R (%Z)\"`"
Kuala Lumpur: 2008-10-31 20:30 (MYT)
export TZ=US/Central; echo "Dallas: `date +\"%F %R (%Z)\"`"
Dallas: 2008-10-31 07:30 (CDT)
export TZ=$OLDTZ

Other valid time strings

date +"%Y%m%d" -d sunday # GNU date
20060709

date +"%Y%m%d" -d last-sunday # GNU date
20060702

date +"%Y%m%d" -d last-week # GNU date
date -v -1m +"%Y%m%d" # BSD date
20060627

date +"%Y%m%d" -d last-month # GNU date
date -v -1w +"%Y%m%d" # BSD date
20060604

date +"%Y%m%d" -d last-year # GNU date
date -v -1y +"%Y%m%d" # BSD date
20050704

date +"%Y%m%d" -d next-week # GNU date
date -v 1w +"%Y%m%d" # BSD date
20060711

date +"%Y%m%d" -d next-month # GNU date
date -v 1m +"%Y%m%d" # BSD date
20060804

date +"%Y%m%d" -d next-year # GNU date
date -v 1y +"%Y%m%d" # BSD date
20070704

To show the time in seconds since 1970-01-01 (Unix epoch):

date +"%s" -d "Fri Apr 24 13:14:39 CDT 2009"
1240596879

To convert Unix epoch time (seconds since 1970-01-01) to a human readable format:

date -d "UTC 1970-01-01 1240596879 secs"
Fri Apr 24 13:14:39 CDT 2009

Or:

date -ud @1000000000
Sun Sep 9 01:46:40 UTC 2001

[edit] Setting the date

The XSI extension to the SUS specifies that the date command can also be used to set the date. The new date is specified as an option to date in the format MMddhhmm[[cc]yy], where MM specifies the two-digit numeric month, dd specifies the two-digit numeric day, hh specifies the two-digit numeric hour, mm specifies the two-digit numeric minutes. Optionally cc specifies the first two digits of the year, and yy specifies the last two digits of the year.

Other Unix and Unix-like systems may set different options or date formats for date, for example, on some systems to set the current date and time to September 8, 2004 01:22 you type:

date --set="20040908 01:22"

[edit] See also

List of Unix programs
Unix time, i.e. number of seconds elapsed since midnight UTC of January 1, 1970 Epoch
time and date
Cron process for scheduling jobs to run on a given date.

[edit] External links

date: write the date and time – Commands & Utilities Reference, The Single UNIX® Specification, Issue 7 from The Open Group
date(1): print or set the system date and time – Linux User Commands Manual
date(1) – FreeBSD General Commands Manual
UNIX date command examples.

[hide]v · d · eUnix command line programs and builtins (more)
File system
cat · cd · chmod · chown · chgrp · cksum · cmp · cp · dd · du · df · file · fsck · fuser · ln · ls · lsattr · lsof · mkdir · mount · mv · pax · pwd · rm · rmdir · size · split · tee · touch · type · umask
Processes
at · bg · chroot · cron · kill · killall · nice · pgrep · pidof · pkill · ps · pstree · time · top
User environment
clear · env · exit · finger · history · id · logname · mesg · passwd · su · sudo · uptime · talk · tput · uname · w · wall · who · whoami · write
Text processing
awk · banner · basename · comm · csplit · cut · dirname · ed · ex · fmt · head · iconv · join · less · more · paste · sed · sort · strings · tail · tr · uniq · vi · wc · xargs
Shell programming
alias · echo · expr · false · printf · sleep · test · true · unset · wait · yes
Networking
dig · inetd · host · ifconfig · netstat · nslookup · ping · rdate · rlogin · netcat · traceroute
Searching
find · grep · locate · whatis · whereis · which
Documentation
apropos · help · info · man
Miscellaneous
bc · cal · date · lp · lpr
List of Unix utilities
Categories: Standard Unix programs | Unix SUS2008 utilities

Log in / create account

Article
Discussion

Read
Edit
View history

Main page
Contents
Featured content
Current events
Random article
Donate to Wikipedia

Interaction

Help
About Wikipedia
Community portal
Recent changes
Contact Wikipedia

Toolbox
Print/export
Languages

Français
日本語
Русский

This page was last modified on 8 May 2011 at 15:40.
Text is available under the Creative Commons Attribution-ShareAlike License; additional terms may apply. See Terms of Use for details.
Wikipedia® is a registered trademark of the Wikimedia Foundation, Inc., a non-profit organization.
Contact us

Privacy policy
About Wikipedia
Disclaimers

Wikimedia Foundation
Powered by MediaWiki


http://en.wikipedia.org/wiki/Date_%28Unix%29

date

date

Display or change the date.

Syntax
date [option]... [+Format]

date [option] [MMDDhhmm[[CC]YY][.ss]]

`date' with no arguments prints the current time and date, in the format of the %c directive (described below).

If given an argument that starts with a +, date prints the current time and date (or the time and date specified by the --date option, see below) in the format defined by that argument, which is the same as in the strftime function.

Except for directives, which start with %, characters in the format string are printed unchanged. The directives are described below.

Options:
-d, --date=String Display time described by String, instead of `now'
this can be in almost any common format.
It can contain month names, timezones, `am' and `pm',
`yesterday', `ago', `next', etc.

-f, --file=DateFile like --date once for each line of DateFile
If DateFile is `-', use standard input. This is
useful when you have many dates to process,
because the system overhead of starting up the
`date' executable many times can be considerable.

-I, --iso-8601[=Timespec] Output an ISO-8601 compliant date/time string., `%Y-%m-%d'.
Timespec=`date' (or missing) for date only,
`hours', `minutes', or `seconds' for date and
time to the indicated precision.
If showing any time terms, then include the time zone
using the format `%z'. If `--utc' is also specified,
use `%Z' in place of `%z'.

-r, --reference=File Display the last modification time of File

-R, --rfc-822 Output RFC-822 compliant date string

-s, --set=String Set time described by String (see -d above)

-u, --utc, --universal Print or set Coordinated Universal Time

--help Display this help and exit
--version output version information and exit


Format controls the output as follows. The only valid option for the second form (MMDDhhmm[[CC]YY][.ss])will specify Coordinated Universal Time.

Interpreted sequences are:

Date:
D Date in mm/dd/yy format (06/14/06)
x Date in standard format for locale (09/12/07 for English-US)

Year:
C Century (20 for 2006)
Y Year in 4-digit format (2006)
y Year in 2-digit format (06)
G Same as 'Y'
g Same as 'y'

Month:
b Month name - abbreviated (Jan)
B Month name - full (January)
h Same as 'b'
m Month number (06)

Week:
W Week of the year (00-52)
V Week of the year (01-53)
U Same as 'W'

Day:
a Day of the week - abbreviated name (Mon)
A Day of the week - full name (Monday)
u Day of the week - number (Monday = 1)
d Day of the month - 2 digits (05)
e Day of the month - digit preceded by a space ( 5)
j Day of the year - (1-366)
w Same as 'u'

Time:
p AM or PM
r Time in 12-hour format (09:15:36 AM)
R Time in 24-hour format - no seconds (17:45)
T Time in 24 hour format (17:45:52)
X Same as 'T'
Z Time zone offset from UTC (-07)

Hour:
H Hour in 24-hour format (17)
I Hour in 12 hour format (05)
k Same as 'H'
l Same as 'I' (Upper-case I = Lower-case L)

Minutes & Seconds:
M Minutes (35)
S Seconds (05)
s Seconds elapsed since January 1, 1970 00:00:00 (1150451174.95705)

Here are the same format codes in alphabetical order:

%% a literal %
%a locale's abbreviated weekday name (Sun..Sat)
%A locale's full weekday name, variable length (Sunday..Saturday)
%b locale's abbreviated month name (Jan..Dec)
%B locale's full month name, variable length (January..December)
%c locale's date and time (Sat Nov 04 12:02:33 EST 1989)
%d day of month (01..31)
%D date (mm/dd/yy)
%e day of month, blank padded ( 1..31)
%h same as %b, locale's abbreviated month name (Jan..Dec)
%H hour :24 hour(00..23)
%I hour :12 hour(01..12)
%j day of year (001..366)
%k hour :24 hour(00..23)
%l hour :12 hour(01..12)
%m month (01..12)
%M minute (00..59)
%n a newline
%p locale's AM or PM
%r time, 12-hour (hh:mm:ss [AP]M)
%s seconds since 00:00:00, Jan 1, 1970 (a GNU extension)
Note that this value is defined by the localtime system
call. It isn't changed by the `--date' option.
%S second (00..60)
%t a horizontal tab
%T time, 24-hour (hh:mm:ss)
%U week number of year with Sunday as first day of week (00..53)
%V week number of year with Monday as first day of week (01..53)
If the week containing January 1 has four or
more days in the new year, then it is considered week 1;
otherwise, it is week 53 of the previous year, and the next week
is week 1. (See the ISO 8601: 1988 standard.)

%w day of week (0..6); 0 represents Sunday
%W week number of year with Monday as first day of week (00..53)
%x locale's date representation (mm/dd/yy)
%X locale's time representation (%H:%M:%S)
%y last two digits of year (00..99)
%Y year (1970...)
%z RFC-822 style numeric timezone (-0500) (a nonstandard extension)
This value reflects the _current_ time zone.
It isn't changed by the `--date' option.
%Z time zone (e.g., EDT), or nothing if no time zone is determinable
This value reflects the _current_ time zone.
It isn't changed by the `--date' option.

By default, date pads numeric fields with zeroes. GNU date recognizes the following modifiers between % and a numeric directive.

- (hyphen) do not pad the field; useful if the output is intended for human consumption.
_ (underscore) pad the field with spaces; useful if you need a fixed number of characters in the output, but zeroes are too distracting.

The - and _ are GNU extensions. Here is an example illustrating the differences:

date +%d/%m -d "Feb 1"
=> 01/02
date +%-d/%-m -d "Feb 1"
=> 1/2
date +%_d/%_m -d "Feb 1"
=> 1/ 2

Setting the time

If given an argument that does not start with +, date sets the system clock to the time and date specified by that argument (as described below). You must have appropriate privileges to set the system clock. The --date and --set options may not be used with such an argument. The --universal option may be used with such an argument to indicate that the specified time and date are relative to Coordinated Universal Time rather than to the local time zone.

The argument must consist entirely of digits, which have the following meaning:

MM month
DD day within month
HH hour
MM minute
CC first two digits of year (optional)
YY last two digits of year (optional)
SS second (optional)

The `--set' option also sets the system clock; see the examples below.

Examples

Print the date of the day before yesterday:
$ date --date='2 days ago'

Rename a file with the current date and time
$ STAMPME=$HOME/demo_file_$(date +%Y%m%d-%H%M).txt
$ mv $HOME/demo_file $STAMPME

Print the date of the day three months and one day hence:
$ date --date='3 months 1 day'

Print the day of year of Christmas in the current year:
$ date --date='25 Dec' +%j

Print the current full month name and the day of the month:
$ date '+%B %d'

But this may not be what you want because for the first nine days of the month, the `%d' expands to a zero-padded two-digit field, for example date -d 1may '+%B %d' will print `May 01'.

* Print a date without the leading zero for one-digit days of the month, you can use the (GNU extension) `-' modifier to suppress the padding altogether.
$ date -d=1may '+%B %-d'

Print the current date and time in the format required by many non-GNU versions of `date' when setting the system clock:
$ date +%m%d%H%M%Y.%S

Set the system date and time
$ date --set="2002-6-29 11:59 AM"

Set the system clock forward by two minutes:
$ date --set='+2 minutes'

Print the date in the format specified by RFC-822, use date --rfc
I just did and saw this:
Mon, 25 Mar 1996 23:34:17 -0600

To convert a date string to the number of seconds since the epoch (which is 1970-01-01 00:00:00 UTC), use the `--date' option with the `%s' format. That can be useful in sorting and/or graphing and/or comparing data by date. The following command outputs the number of the seconds since the epoch for the time one second later than the epoch, but in time zone five hours later (Cambridge, Massachusetts), thus a total of five hours and one second after the epoch:

$ date --date='1970-01-01 00:00:01 UTC +5 hours' +%s
18001

Suppose you had _not_ specified time zone information in the example above. Then, date would have used your computer's idea of
the time zone when interpreting the string. Here's what you would get if you were in Greenwich, England:

# local time zone used
$ date --date='1970-01-01 00:00:01' +%s
1

If you're sorting or graphing dated data, your raw date values may be represented as seconds since the epoch. But few people can
look at the date `946684800' and casually note "Oh, that's the first second of the year 2000."

$ date --date='2000-01-01 UTC' +%s
946684800

To convert such an unwieldy number of seconds back to a more readable form, use a command like this:

$ date -d '1970-01-01 946684800 sec' +"%Y-%m-%d %T %z"
2000-01-01 00:00:00 +0000

"Carpe Diem - Seize the day" - Horace

Related:

cal - Display a calendar
crontab - Schedule a command to run at a later time
time - Measure Program Resource Use
times - User and system times
touch - Change file timestamps
Equivalent Windows command: DATE - Display or set the dat

******************
http://ss64.com/bash/date.html

25540411

puppy-linux

http://distro.ibiblio.org/pub/linux/distributions/puppylinux/
http://ftp.nluug.nl/ftp/pub/os/Linux/distr/puppylinux/

25540401

puppy, linux

adrss: /etc/X11
filename:xorg.conf
hardware: ECS A780GM-A, AMD, Athlon 4800+




****************************************************

#Special base config file used in Puppy Linux.

# **********************************************************************
# Module section -- this section is used to specify
# which dynamically loadable modules to load.
# **********************************************************************
#
Section "Module"

# This loads the DBE extension module.

Load "dbe" # Double buffer extension

# This loads the miscellaneous extensions module, and disables
# initialisation of the XFree86-DGA extension within that module.
SubSection "extmod"
Option "omit xfree86-dga" # don't initialise the DGA extension
EndSubSection

# This loads the font modules
Load "type1"
Load "freetype"

# This loads xtrap extension, used by xrandr
Load "xtrap"

# This loads the GLX module (if present)
Load "glx"

# This loads dri module (if present)
Load "dri"

EndSection

# **********************************************************************
# Files section. This allows default font and rgb paths to be set
# **********************************************************************

Section "Files"

# The location of the RGB database. Note, this is the name of the
# file minus the extension (like ".txt" or ".db"). There is normally
# no need to change the default.

RgbPath "/usr/X11R7/lib/X11/rgb"

# Multiple FontPath entries are allowed (which are concatenated together),
# as well as specifying multiple comma-separated entries in one FontPath
# command (or a combination of both methods)

FontPath "/usr/X11R7/lib/X11/fonts/misc/"
FontPath "/usr/X11R7/lib/X11/fonts/Type1/"
FontPath "/usr/X11R7/lib/X11/fonts/TTF/"

EndSection

# **********************************************************************
# Server flags section.
# **********************************************************************

Section "ServerFlags"

# Uncomment this to disable the VT switch sequence
# (where n is 1 through 12). This allows clients to receive these key
# events.

# Option "DontVTSwitch"

# Enables mode switching with xrandr
# There is a report that this can cause Xorg not to work on some
# video hardware, so default is commented-out...
# but i want to use it in xorgwizard so leave on...

Option "RandR" "on"

EndSection

#everything past here is auto-generated by Puppy's Xorg Wizard...


Section "ServerLayout"
Identifier "X.org Configured"
Screen 0 "Screen0" 0 0
InputDevice "Mouse0" "CorePointer"
InputDevice "Keyboard0" "CoreKeyboard"
EndSection

Section "InputDevice"
Identifier "Keyboard0"
Driver "kbd"
Option "XkbRules" "xorg"
Option "XkbModel" "pc102"
Option "XkbLayout" "us,th" #xkeymap0
Option "XkbOptions" "grp:alt_shift_toggle,grp_led:scroll"
EndSection

Section "InputDevice"
Identifier "Mouse0"
Driver "mouse"
Option "Protocol" "auto" #mouse0protocol
Option "Device" "/dev/mouse"
#Option "Emulate3Buttons"
#Option "Emulate3Timeout" "50"
Option "ZAxisMapping" "4 5" #scrollwheel
EndSection

Section "Monitor"
Identifier "Monitor0"
VendorName "Monitor Vendor"
ModelName "Monitor Model"
HorizSync 30-70
VertRefresh 56-85
#UseModes "Modes0" #monitor0usemodes
Option "PreferredMode" "1024x768"
EndSection

Section "Modes"
Identifier "Modes0"
#modes0modeline0
EndSection

Section "Device"
### Available Driver options are:-
### Values: : integer, : float, : "True"/"False",
### : "String", : " Hz/kHz/MHz"
### [arg]: arg optional
#Option "ShadowFB" # []
#Option "DefaultRefresh" # []
#Option "ModeSetClearScreen" # []
Identifier "Card0"
Driver "vesa" #card0driver
VendorName "ATI Technologies Inc"
BoardName "Unknown Board"
BusID "PCI:1:5:0"
EndSection

Section "Screen"
Identifier "Screen0"
Device "Card0"
Monitor "Monitor0"
DefaultDepth 16
Subsection "Display"
Depth 16
Modes "1024x768"
EndSubsection
EndSection

#PuppyHardwareProfile=ATI_ATOMBIOS371999

25540329

rar,unrar,linux

http://www.cyberciti.biz/faq/open-rar-file-or-extract-rar-files-under-linux-or-unix/


Open rar file or Extract rar files under Linux or UNIX


by Vivek Gite on February 8, 2006 · 132 comments






Q. How do I open rar archive files under Linux / UNIX operating systems?



A. RAR files are in compressed archive format, if you have downloaded rar files from the Internet, you need to unpack or unrar them (extract rar files).


RAR is a proprietary file format for data compression and archiving, developed by Eugene Roshal.


Under Linux and UNIX, use command called unrar. By default unrar is not being installed on Linux, FreeBSD or UNIX oses. You can install unrar command with the help of apt-get or yum command.


(See below for Windows XP info)


Install unrar command


Under Debian Linux, you need to type apt-get as follows to install unrar program:

# apt-get install unrar


If you are using Fedora core Linux then use yum command as follows (see discussion below):

# yum install unrar



If you are using FreeBSD, use:

# pkg_add -v -r unrar


If any of above, methods is not working for you, download binary package from official rarlab site:

$ cd /tmp

$ wget http://www.rarlab.com/rar/rarlinux-3.6.0.tar.gz


Untar file

$ tar -zxvf rarlinux-3.6.0.tar.gz


Both unrar and rar commands are located in rar sub-directory. Just go to rar directory:


$ cd rar

$ ./unrar


Now copy rar and unrar to /bin directory:

# cp rar unrar /bin


How to use unrar


unrar command supports various options below are common options that you need to use everyday.


Task: To open rar (unpack) file in current directory type command:


$ unrar e file.rar


Please note that replace file.rar filename with your actual filename.



Task: List (l) file inside rar archive:


$ unrar l file.rar


Task: To extract (x) files with full path type command:


$ unrar x file.rar


(D) To test (t) integrity of archive, file type command:

$ unrar t file.rar




How do I open rar file under Windows XP/NT/2000?


Windows XP or NT/2000 user




  • If you are using Windows XP then I recommend to download Winrar. It is free download ( Free to try License) software.

25530604

linux

default vmlinuz initrd=initrd.gz pmedia=usbflash pfix=copy nosmp