Академический Документы
Профессиональный Документы
Культура Документы
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
stat <file-name> # Last modification time stamps, permissions, and size of a file
whoami
hostname
up(down)_key
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
:w # save command; if you are in editing mode you have to hit ESC first!!
R # replace MODE
q: # history of commands (from NORMAL MODE!), to reexecute one of them, select and
hit enter!
Deleting Things
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
2dd # deletes next two lines, continues: 3dd, 4dd and so on.
Search in Files
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
Extracting Archives
cat
cat .bashrc
cd
cd /home
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
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
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
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