Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
147 views

Unix/Linux Command Reference: File Commands System Info

This document provides a summary of common Linux/Unix commands organized by category including file commands, system info commands, compression commands, process management commands, file permissions commands, SSH commands, searching commands, and installation commands. It also includes shortcuts and examples of using commands together to automate tasks or run commands in the background.

Uploaded by

tesnukare
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
147 views

Unix/Linux Command Reference: File Commands System Info

This document provides a summary of common Linux/Unix commands organized by category including file commands, system info commands, compression commands, process management commands, file permissions commands, SSH commands, searching commands, and installation commands. It also includes shortcuts and examples of using commands together to automate tasks or run commands in the background.

Uploaded by

tesnukare
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Unix/Linux Command Reference

File Commands

.com
System Info

ls directory listing
date show the current date and time
ls -al formatted listing with hidden files
cal show this month's calendar
cd dir - change directory to dir
uptime show current uptime
cd change to home
w display who is online
pwd show current directory
whoami who you are logged in as
mkdir dir create a directory dir
finger user display information about user
rm file delete file
uname -a show kernel information
rm -r dir delete directory dir
cat /proc/cpuinfo cpu information
rm -f file force remove file
cat /proc/meminfo memory information
rm -rf dir force remove directory dir *
man command show the manual for command
cp file1 file2 copy file1 to file2
df show disk usage
cp -r dir1 dir2 copy dir1 to dir2; create dir2 if it du show directory space usage
doesn't exist
free show memory and swap usage
mv file1 file2 rename or move file1 to file2
whereis app show possible locations of app
if file2 is an existing directory, moves file1 into
which app show which app will be run by default
directory file2
Compression
ln -s file link create symbolic link link to file
tar cf file.tar files create a tar named
touch file create or update file
file.tar containing files
cat > file places standard input into file
tar xf file.tar extract the files from file.tar
more file output the contents of file
tar czf file.tar.gz files create a tar with
head file output the first 10 lines of file
Gzip compression
tail file output the last 10 lines of file
tar xzf file.tar.gz extract a tar using Gzip
tail -f file output the contents of file as it
tar cjf file.tar.bz2 create a tar with Bzip2
grows, starting with the last 10 lines
compression
Process Management
tar xjf file.tar.bz2 extract a tar using Bzip2
ps display your currently active processes
gzip file compresses file and renames it to
top display all running processes
file.gz
kill pid kill process id pid
gzip -d file.gz decompresses file.gz back to
killall proc kill all processes named proc *
file
bg lists stopped or background jobs; resume a
stopped job in the background
Network
fg brings the most recent job to foreground
ping host ping host and output results
fg n brings job n to the foreground
whois domain get whois information for domain
dig domain get DNS information for domain
File Permissions
dig -x host reverse lookup host
chmod octal file change the permissions of file
wget file download file
to octal, which can be found separately for user,
wget -c file continue a stopped download
group, and world by adding:
4 read (r)
Installation
2 write (w)
Install from source:
1 execute (x)
./configure
Examples:
make
chmod 777 read, write, execute for all
make install
chmod 755 rwx for owner, rx for group and world
dpkg -i pkg.deb install a package (Debian)
For more options, see man chmod.
rpm -Uvh pkg.rpm install a package (RPM)

SSH

ssh user@host connect to host as user


ssh -p port user@host connect to host on port
port as user
ssh-copy-id user@host add your key to host for
user to enable a keyed or passwordless login

Searching

Shortcuts

Ctrl+C halts the current command


Ctrl+Z stops the current command, resume with
fg in the foreground or bg in the background
Ctrl+D log out of current session, similar to exit
Ctrl+W erases one word in the current line
Ctrl+U erases the whole line
Ctrl+R type to bring up a recent command
!! - repeats the last command
exit log out of current session

grep pattern files search for pattern in files


grep -r pattern dir search recursively for
pattern in dir
command | grep pattern search for pattern in the
output of command
* use with extreme caution.
locate file find all instances of file

(works with about every distribution, except for apt-get which is Ubuntu/Debian exclusive)

Linux Bash Shell


Cheat Sheet

freeworld.posterous.com

Legend:

Everything in <> is to be replaced, ex: <fileName> --> iLovePeanuts.txt


Don't include the '=' in your commands
'..' means that more than one file can be affected with only one command ex: rm
file.txt file2.txt movie.mov .. ..

mv
mv
mv
mv
mv

cp
cp
cp
cp

<fileName> .. = delete file (s)


-i <fileName> .. = ask for confirmation each file
-f <fileName> = force deletion of a file
-r <foldername>/ = delete folder

file.txt Documents/ = move file to a folder


<folderName> <folderName2> = move folder in folder
filename.txt filename2.txt = rename file
<fileName> stuff/newfileName
<folderName>/ .. = move folder up in hierarchy

image.jpg <folderName>/ = copy to folder


image.jpg folder/sameImageNewName.jpg
-R stuff otherStuff = copy and rename a folder
*.txt stuff/ = copy all of *<file type> to folder

ln file1 file2 = physical link


ln -s file1 file2 = symbolic link

touch <fileName> = create or update a file

rm
rm
rm
rm

cp image.jpg newimage.jpg = copy and rename a file

mkdir = create new folder


mkdir myStuff ..
mkdir myStuff/pictures/ ..

tail = from the bottom


-n <#oflines> <fileName>

cat <fileName> = show content of file


(less, more)
head = from the top
-n <#oflines> <fileName>

Basic file manipulation

Basic Commands

Linux Bash Shell Cheat Sheet


Basic Terminal Shortcuts
CTRL L = Clear the terminal
CTRL D = Logout
SHIFT Page Up/Down = Go up/down the terminal
CTRL A = Cursor to start of line
CTRL E = Cursor the end of line
CTRL U = Delete left of the cursor
CTRL K = Delete right of the cursor
CTRL W = Delete word on the left
CTRL Y = Paste (after CTRL U,K or W)
TAB = auto completion of file or command
CTRL R = reverse search history
!! = repeat last command
CTRL Z = stops the current command (resume with fg in foreground or bg in background)

-a = list all files and folders


<folderName> = list files in folder
-lh = Detailed list, Human readable
-l *.jpg = list jpeg files only
-lh <fileName> = Result for file only

Basic Terminal Navigation


ls
ls
ls
ls
ls

cd <folderName> = change directory


if folder name has spaces use
cd / = go to root
cd .. = go up one folder, tip: ../../../
du -h: Disk usage of folders, human readable
du -ah:

files & folders, Human readable


du -sh: only show disc usage of folders
pwd = print working directory
man <command> = shows manual (RTFM)

Linux Bash Shell Cheat Sheet


Researching Files

Extract, sort and filter data

Basic Commands

The slow method (sometimes very slow):

best file search tool (fast)


<fileName>
text = search for files who start with the word text
*text =

end

grep
with
grep
grep
with

= sort the content of files


<fileName> = sort alphabetically
-o <file> <outputFile> = write result to a file
-r <fileName> = sort in reverse
-R <fileName> = sort randomly
-n <fileName> = sort numbers

-E ^<text> <fileName> = search start of lines


the word text
-E <0-4> <fileName> =shows lines containing numbers 0-4
-E <a-zA-Z> <fileName> = retrieve all lines
alphabetical letters

wc = word count
wc <fileName> = nbr of line, nbr of words, byte size
-l (lines), -w (words), -c (byte size), -m
(number of characters)

sort
sort
sort
sort
sort
sort

With regular expressions:

grep <someText> <fileName> = search for text in file


-i = Doesn't consider uppercase words
-I = exclude binary files
grep -r <text> <folderName>/ = search for file names
with occurrence of the text

= the
-name
-name
-name

locate <text> = search the content of all the files


locate <fileName> = search for a file
sudo updatedb = update database of files
find
find
find
find

Advanced Search:
Search from file Size (in ~)
find ~ -size +10M = search files bigger than.. (M,K,G)
Search from last access
find -name <filetype> -atime -5
('-' = less than, '+' = more than and nothing = exactly)
Search only files or directorys
find -type d --> ex: find /var/log -name "syslog" -type d
find -type f = files
More info: man find, man locate

cut = cut a part of a file


-c --> ex: cut -c 2-5 names.txt
(cut the characters 2 to 5 of each line)
-d (delimiter)
(-d & -f good for .csv files)
-f (# of field to cut)

more info: man cut, man sort, man grep

Linux Bash Shell Cheat Sheet


Time settings

(continued)

Basic Commands

date = view & modify time (on your computer)

Add a '&' at the end of a command


ex --> cp bigMovieFile.mp4 &

Execute programs in the background

30 5 1-15 * *
at midnight on Mondays, Wednesdays and Thursdays:
0 0 * * 1,3,4
every two hours:
0 */2 * * *
every 10 minutes Monday to Friday:
*/10 * * * 1-5

ex, create the file movies.txt every day at 15:47:


47 15 * * * touch /home/bob/movies.txt
* * * * * --> every minute
at 5:30 in the morning, from the 1st to 15th each month:

crontab = execute a command regularly


-e = modify the crontab
-l = view current crontab
-r = delete you crontab
In crontab the syntax is
<Minutes> <Hours> <Day of month> <Day of week (0-6,
0 = Sunday)> <COMMAND>

View:
date +%H --> If it's 9 am, then it will show 09
date +%H:%M:%Ss = (hours, minutes, seconds)
%Y = years
Modify:
MMDDhhmmYYYY
Month | Day | Hours | Minutes | Year
sudo date 031423421997 = March 14 th 1997, 23:42

Execute programs at another time


use 'at' to execute programs in the future
Step 1, write in the terminal: at <timeOfExecution> ENTER
ex --> at 16:45 or at 13:43 7/23/11 (to be more precise)
or after a certain delay:
at now +5 minutes (hours, days, weeks, months, years)
Step 2: <ENTER COMMAND> ENTER
repeat step 2 as many times you need
Step 3: CTRL D to close input

nohup: ignores the HUP signal when closing the console


(process will still run if the terminal is closed)
ex --> nohup cp bigMovieFile.mp4

atq = show a list of jobs waiting to be executed


atrm = delete a job n<x>
ex (delete job #42) --> atrm 42

fg = put a background process to foreground


ex: fg (process 1), f%2 (process 2) f%3, ...

jobs = know what is running in the background

sleep = pause between commands


with ';' you can chain commands, ex: touch file; rm file
you can make a pause between commands (minutes, hours, days)
ex --> touch file; sleep 10; rm file <-- 10 seconds

You might also like