Вы находитесь на странице: 1из 11

To copy files To the server run the following on your workstation or laptop:

scp -r <path_to_directory> <your_username>@<host_name>:

To copy files From the server run the following on your workstation or laptop:

scp -r <your_username>@<host_name>:<path_to_directory> .

pwd

# Get full path of the present working directory (same as "echo $HOME")

pwd

# Get full path of the present working directory (same as "echo $HOME")

ls
ls -l
ls -a
ls -R
ls -t

# Content of pwd
# Similar as ls, but provides additional info on files and directories
# Includes hidden files (.name) as well
# Lists subdirectories recursively
# Lists files in chronological order

cd <dir_name> # Switches into specified directory.


cd
# Brings you to the highest level of your home directory.
cd ..
# Moves one directory up
cd ../../
# Moves two directories up (and so on)
cd # Go back to you were previously (before the last directory change)
echo ~
find ~
ls ~

# View the full (complete) path of your home


# List all your files (including everything in sub-directories)
# List the top level files of your home directory

stat <file-name> # Last modification time stamps, permissions, and size of a file
whoami
hostname

# Shows your user name (same as "echo $USER")


# Shows on which machine you are (same as "echo $HOSTNAME")

mkdir <dir_name> # Creates specified directory


rmdir <dir_name> # Removes empty directory
rm <file_name> # Removes file name
rm -r <dir_name> # Removes directory including its content, but asks for confirmation,
# 'f' argument turns confirmation off
cp <name> <path> # Copy file/directory as specified in path (-r to include content in
directories)
mv <name1> <name2> # Renames directories or files
mv <name> <path> # Moves file/directory as specified in path
history # shows all commands you have used recently

up(down)_key

- scrolls through command history

man <something> # general help (press the 'q' key to exit)


man wc
# manual on program 'word count' wc
wc --help
# short help on wc
find -name "*pattern*"
# searches for *pattern* in and below current directory
find /usr/local -name "*blast*" # finds file names *blast* in specfied directory
find /usr/local -iname "*blast*" # same as above, but case insensitive
find ~ -type f -mtime -2 # finds all files you have modified in the last two days
locate <pattern>
# finds files and dirs that are written into update file
which <application_name> # location of application
whereis <application_name> # searches for executeables in set of directories
dpkg -l | grep mypattern # find Debian packages and refine search with grep pattern
grep pattern file

# provides lines in 'file' where pattern 'appears',


# if pattern is shell function use single-quotes: '>'

grep -H pattern
# -H prints out file name in front of pattern
grep 'pattern' file | wc # pipes lines with pattern into word count wc (see chapter 8)
# wc arguments: -c: show only bytes, -w: show only words,
# -l: show only lines; help on regular expressions:
# $ man 7 regex or man perlre

find /home/my_dir -name '*.txt' | xargs grep -c ^.* # counts line numbers on many
# files and records each count along with individual file
# name; find and xargs are used to circumvent the Linux
# wildcard limit to apply this function on thousands of files.
chown <user> <file or dir>
# changes user ownership
chgrp <group> <file or dir>
# changes group ownership
chown <user>:<group> <file or dir> # changes user & group ownership
df
# disk space
free -g # memory info in Megabytes
uname -a # shows tech info about machine
bc
# command-line calculator (to exit type 'quit')
wget ftp://ftp.ncbi.nih.... # file download from web
/sbin/ifconfig # give IP and other network info
ln -s original_filename new_filename # creates symbolic link to file or directory
du -sh
# displays disk space usage of current directory
du -sh * # displays disk space usage of individual files/directories
du -s * | sort -nr # shows disk space used by different directories/files sorted by size

Process management:
top
# view top consumers of memory and CPU (press 1 to see per-CPU statistics)
who
# Shows who is logged into system
w
# Shows which users are logged into system and what they are doing
ps
# Shows processes running by user
ps -e
# Shows all processes on system; try also '-a' and '-x' arguments
ps aux | grep <user_name> # Shows all processes of one user
ps ax --tree
# Shows the child-parent hierarchy of all processes
ps -o %t -p <pid> # Shows how long a particular process was running.
# (E.g. 6-04:30:50 means 6 days 4 hours ...)
Ctrl z <enter> # Suspend (put to sleep) a process
fg
# Resume (wake up) a suspended process and brings it into foreground
bg
# Resume (wake up) a suspended process but keeps it running
# in the background.
Ctrl c
# Kills the process that is currently running in the foreground
kill <process-ID> # Kills a specific process
kill -9 <process-ID> # NOTICE: "kill -9" is a very violent approach.
# It does not give the process any time to perform cleanup procedures.
kill -l
# List all of the signals that can be sent to a proccess
kill -s SIGSTOP <process-ID> # Suspend (put to sleep) a specific process
kill -s SIGCONT <process-ID> # Resume (wake up) a specific process
renice -n <priority_value> # Changes the priority value, which range from 1-19,
# the higher the value the lower the priority, default is 10.
Text viewing:
more <my_file> # views text, use space bar to browse, hit 'q' to exit
less <my_file> # a more versatile text viewer than 'more', 'q' exits, 'G' moves to end of text, 'g'
to beginning, '/' find forward, '?' find backwards
cat <my_file> # concatenates files and prints content to standard output
vim my_file_name # open/create file with vim
Modifier Keys to Control Vim

i # INSERT MODE

ESC # NORMAL (NON-EDITING) MODE

: # commands start with ':'

:w # save command; if you are in editing mode you have to hit ESC first!!

:q # quit file, don't save

:q! # exits WITHOUT saving any changes you have made

:wq # save and quit

R # replace MODE

r # replace only one character under cursor

q: # history of commands (from NORMAL MODE!), to reexecute one of them, select and
hit enter!

:w new_filename # saves into new file

:#,#w new_filename # saves specific lines (#,#) to new file

:# go to specified line number

Undo and Redo

u # undo last command

U # undo all changes on current line

CTRL-R # redo one change which was undone


Table of Contents

Deleting Things

x # deletes what is under cursor

dw # deletes from curser to end of word including the space

de # deletes from curser to end of word NOT including the space

cw # deletes rest of word and lets you then insert, hit ESC to continue with NORMAL
mode

c$ # deletes rest of line and lets you then insert, hit ESC to continue with with NORMAL
mode

d$ # deletes from cursor to the end of the line

dd # deletes entire line

2dd # deletes next two lines, continues: 3dd, 4dd and so on.

Copy & Paste

yy # copies line, for copying several lines do 2yy, 3yy and so on

p # pastes clipboard behind cursor

Search in Files

/my_pattern # searches for my_pattern downwards, type n for next match

?my_pattern # seraches for my_pattern upwards, type n for next match

:set ic # switches to ignore case search (case insensitive)

:set hls # switches to highlight search (highlights search hits)

cat <file1> <file2> > <cat.out>


# concatenate files in output file 'cat.out'
paste <file1> <file2> > <paste.out> # merges lines of files and separates them by tabs
(useful for tables)
cmp <file1> <file2>
# tells you whether two files are identical
diff <fileA> <fileB>
# finds differences between two files
head -<number> <file>
# prints first lines of a file
tail -<number> <file>
# prints last lines of a file
split -l <number> <file>
# splits lines of file into many smaller ones
csplit -f out fasta_batch "%^>%" "/^>/" "{*}" # splits fasta batch file into many files
# at '>'
sort <file>
# sorts single file, many files and can merge (-m)
# them, -b ignores leading white space, ...
sort -k 2,2 -k 3,3n input_file > output_file # sorts in table column 2 alphabetically and
# column 3 numerically, '-k' for column, '-n' for
# numeric
sort input_file | uniq > output_file # uniq command removes duplicates and creates
file/table
# with unique lines/fields
join -1 1 -2 1 <table1> <table2> # joins two tables based on specified column numbers
# (-1 file1, 1: col1; -2: file2, col2). It assumes
# that join fields are sorted. If that is not the case,
# use the next command:
sort table1 > table1a; sort table2 > table2a; join -a 1 -t "`echo -e '\t'`" table1a table2a >
table3
# '-a <table>' prints all lines of specified table!
# Default prints only all lines the two tables have in
# common. '-t "`echo -e '\t'`" ->' forces join to
# use tabs as field separator in its output. Default is
# space(s)!!!
cat my_table | cut -d , -f1-3
# cut command prints only specified sections of a table,
# -d specifies here comma as column separator (tab is
# default), -f specifies column numbers.

wget: File Download from the Web


wget ftp://ftp.ncbi.nih.... # file download from www; add option '-r' to download entire directories

Creating Archives

tar -cvf my_file.tar mydir/ # Builds tar archive of files or directories. For directories, execute
command in parent directory. Don't use absolute path.
tar -czvf my_file.tgz mydir/ # Builds tar archive with compression of files or directories. For
# directories, execute command in parent directory. Don't use absolute path.
zip -r mydir.zip mydir/
# Command to archive a directory (here mydir) with zip.
tar -jcvf mydir.tar.bz2 mydir/ # Creates *.tar.bz2 archive
Viewing Archives

tar -tvf my_file.tar


tar -tzvf my_file.tgz

Extracting Archives

tar -xvf my_file.tar


tar -xzvf my_file.tgz
gunzip my_file.tar.gz # or unzip my_file.zip, uncompress my_file.Z,
# or bunzip2 for file.tar.bz2
find -name '*.zip' | xargs -n 1 unzip # this command usually works for unzipping
# many files that were compressed under Windows
tar -jxvf mydir.tar.bz2 # Extracts *.tar.bz2 archive
Try also:
tar zxf blast.linux.tar.Z
tar xvzf file.tgz

cat
cat .bashrc
cd
cd /home

Sends file contents to standard output. This is a way to list the


contents of short files to the screen. It works well with piping.
Sends the contents of the ".bashrc" file to the screen.
Change directory
Change the current working directory to /home. The '/'
indicates relative to root, and no matter what directory you are
in when you execute this command, the directory will be

cp

dd

df
less
ln

locate

logout
ls

changed to "/home".
cd httpd
Change the current working directory to httpd, relative to the
current location which is "/home". The full path of the new
working directory is "/home/httpd".
cd ..
Move to the parent directory of the current directory. This
command will make the current working directory "/home.
cd ~
Move to the user's home directory which is "/home/username".
The '~' indicates the users home directory.
Copy files
cp myfile yourfile
Copy the files "myfile" to the file "yourfile" in the current
working directory. This command will create the file "yourfile"
if it doesn't exist. It will normally overwrite it without warning
if it exists.
cp -i myfile yourfile With the "-i" option, if the file "yourfile" exists, you will be
prompted before it is overwritten.
cp -i /data/myfile .
Copy the file "/data/myfile" to the current working directory
and name it "myfile". Prompt before overwriting the file.
cp -dpr srcdir destdir Copy all files from the directory "srcdir" to the directory
"destdir" preserving links (-p option), file attributes (-p
option), and copy recursively (-r option). With these options, a
directory and all it contents can be copied to another directory.
Disk duplicate. The man page says this command is to
dd if=/dev/hdb1
"Convert and copy a file", but although used by more
of=/backup/
advanced users, it can be a very handy command. The "if"
means input file, "of" means output file.
Show the amount of disk space used on each mounted
filesystem.
Similar to the more command, but the user can page up and
less textfile
down through the file. The example displays the contents of
textfile.
Creates a symbolic link to a file.
ln -s test symlink
Creates a symbolic link named symlink that points to the file
test Typing "ls -i test symlink" will show the two files are
different with different inodes. Typing "ls -l test symlink" will
show that symlink points to the file test.
A fast database driven file locator.
slocate -u
This command builds the slocate database. It will take several
minutes to complete this command. This command must be
used before searching for files, however cron runs this
command periodically on most systems.
locate whereis
Lists all files whose names contain the string "whereis".
Logs the current user off the system.
List files
ls
List files in the current working directory except those starting
with . and only show the file name.

ls -al

List all files in the current working directory in long listing


format showing permissions, ownership, size, and time and
date stamp
more
Allows file contents or piped output to be sent to the screen
one page at a time.
more /etc/profile
Lists the contents of the "/etc/profile" file to the screen one
page at a time.
ls -al |more
Performs a directory listing of all files and pipes the output of
the listing through more. If the directory listing is longer than a
page, it will be listed one page at a time.
mv
Move or rename files
mv -i myfile yourfile Move the file from "myfile" to "yourfile". This effectively
changes the name of "myfile" to "yourfile".
mv -i /data/myfile . Move the file from "myfile" from the directory "/data" to the
current working directory.
pwd
Show the name of the current working directory
more /etc/profile
Lists the contents of the "/etc/profile" file to the screen one
page at a time.
shutdown
Shuts the system down.
shutdown -h now
Shuts the system down to halt immediately.
shutdown -r now
Shuts the system down immediately and the system reboots.
whereis
Show where the binary, source and manual page files are for a
command
whereis ls
Locates binaries and manual pages for the ls command.

Uname command:
The uname command stands for (Unix Name), print detailed information about the machine name, Operating
System and Kernel.

uname -a
ifconfig
The sudo (super user do) command allows a permitted user to execute a command as the superuser or another
user, as specified by the security policy in the sudoers list.

mkdir tecmint
The touch command stands for (Update the access and modification times of each FILE to the current
time). touch command creates the file, only if it doesnt exist. If the file already exists it will update the timestamp and
not the contents of the file.
touch filename

The Linux chmod command stands for (change file mode bits). chmod changes the file mode (permission) of
each given file, folder, script, etc.. according to mode asked for.
There exist 3 types of permission on a file (folder or anything but to keep things simple we will be using file).
Read (r)=4
Write(w)=2
Execute(x)=1

So if you want to give only read permission on a file it will be assigned a value of 4, for write permission only, a value
of 2 and for execute permission only, a value of 1 is to be given. For read and write permission 4+2 = 6 is to be
given, ans so on.
Now permission need to be set for 3 kinds of user and usergroup. The first is owner, then usergroup and finally world.
rwxr-x--x abc.sh

rwx (read, write and execute).


r-x (read and execute only, no write permission) and
for world is x (only execute).
Here the roots permission is

usergroup to which it belongs, is

To change its permission and provide

read, write and execute permission to owner, group and world.

root@tecmint:~# chmod 777 abc.sh


only

read and write permission to all three.

root@tecmint:~# chmod 666 abc.sh

read, write and execute to owner and only execute to group and world.
root@tecmint:~# chmod 711 abc.sh

Command: chown
The Linux chown command stands for (change file owner and group). Every file belongs to a
group of user and a owner. It is used Do ls -l into your directory and you will see something like
this.

root@tecmint:~# ls -l

drwxr-xr-x 3 server root 4096 May 10 11:14 Binary


drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop
Here the directory Binary is owned by user server and it belongs to usergroup root where as
directory Desktop is owned by user server and belongs to user group server.
This chown command is used to change the file ownership and thus is useful in managing and
providing file to authorised user and usergroup only.
root@tecmint:~# chown server:server Binary

drwxr-xr-x 3 server server 4096 May 10 11:14 Binary


drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop
Command: tar
The tar command is a Tape Archive is useful in creation of archive, in a number of file format
and their extraction.
root@tecmint:~# tar -zxvf abc.tar.gz (Remember 'z' for .tar.gz)
root@tecmint:~# tar -jxvf abc.tar.bz2 (Remember 'j' for .tar.bz2)
root@tecmint:~# tar -cvf archieve.tar.gz(.bz2) /path/to/folder/abc

cal
how calendar of year 1835 for month February, that already has passed.
root@tecmint:~# cal 02 1835

February 1835
Su Mo Tu We Th Fr Sa

1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
date
Link: http://www.tecmint.com/useful-linux-commands-for-newbies/
http://doors.stanford.edu/~sr/computing/basic-unix.html
http://www.debianhelp.co.uk/commands.htm

Вам также может понравиться