Thursday, January 23, 2014

List of useful Linux terminal shortcut / commands / tips

list of useful command in Linux (Ubuntu, Suse, Redhat, ...)

NOTES
Open a new terminal:
  • Applications menu -> Accessories -> Terminal.
  • Ctrl + Alt + T
  • Ctrl + Shift + T: open a new tab
$ gksudo nautilus    open Folder Explorer

INSTALL NEW PACKAGE OR SOFTWARE
After download .tar.gz file
$ tar –xvzf Folder.tar.gz
----------------------------------------------------------------
install software, application if they provide .sh file in the folder
$ sudo ./install.sh 
----------------------------------------------------------------
Install with "makefile" or "configure" folder
$ cd SofwareFolder
$ ./configure
$ make
$ make install
----------------------------------------------------------------
OS Group 1: RedHat, Fedora, SUSE, CentOS,  .rpm extension
rpm -Uvh File.rpm
OS Group 2:  Debian, Ubuntu
.deb extension

$ lsb_release -a     check Linux system operation version and detail

MOUNT ISO IMAGE ON LINUX

$ sudo su

$ mkdir -p /mnt/ISO_Disk                                 create a folder on the disk
$ mount -o loop Path/To/*.iso /mnt/ISO_Disk   mount iso file to the folder
$ umount /mnt/ISO_Disk                                  unmount Iso from the folder

USEFUL SHORTCUTS : to saving time

Ctrl + R: search the commands you have used before
Ctrl + A : go (move cursor) to the beginning of command line
Ctrl + E : go (move cursor) to the ending of command line

Ctrl + U : erase the whole text on the current command line (to input new one)
Ctrl + W : delete a word before the cursor
Ctrl + K :  delete text from the cursor position to the end of the line
Ctrl + L :  clear whole terminal screen
Ctrl + C :  exit the previous command
Ctrl + Z:  escape from previous command (halt), but not applied for all especially displace

Up Arrow: move forward one previous command
Down Arrow: move backward one next command (till the last one only)
Enter: to run commands
Ctrl + D: exit , log out of a session

When open Folder Explorer: press Ctrl + H to view all hidden files

COMMAND

COMMAND -?  command --help :   to see a command help, e.g., cd -?
man COMMAND:  read command help

HARDWARE
cat /proc/cpuinfo | grep processor               show each processor separately

cat /proc/cpuinfo | grep processor | wc -l     find number of processors in linux
free: memory info, free and usage, i.e., free -m
du: folder/file size
df -h: all disk space usage
lsb_release -a: Linux version and system information
uname -a:  system information
uname -m:  system structure 32 or 64 bit



history: view a list of previously used command
!number: after running the "history" command, it shows the line number in the first column and the corresponding command in the second column, you can use this command to with the line number to reuse the previous command without typing the whole command again, i.e., !102

sudo : login as root (admin)
sudo (make/ ...) : add sudo before the command to have powerful-administrative access (remove permission denied)

export PATH=$PATH:/home/me/bin:/usr/bin      : environment variable in .bashrc
USER_PATH='/home/user' : assign a new environmental variables (must be in UPPERCASE), e.g. USER_PATH, with the path as specified
unset USER_PATH:  remove a environmental variable

sudo gedit /etc/fstab    edit drive manage file
cd /dev                         go to disk drive directory
ls hd*                            show all internal drive
ls s*                              show all external drive
mount | grep sda3          mount an external drive
umount -l /dev/sda2       unmount an external drive
sudo mkdir /media/sda3                      create directory to mount
sudo mount /dev/sda2 /media/sda2      mount external drive manually on the disk directory

sudo fdisk /dev/sda     format hard disk in linux,

chmod: change file mode bits
cal : (calendar) appear whole current month
date :  appear date
hostname : host name or the NIS domain name
passwd: update a user's authentication, password
which COMMAND: locate a command
whoami : Print the user name associated with the current effective user ID
who : Print information about users who are currently logged in.
echo: display a line of text
echo "$PATH": display all path

cd :  access a directory
(cd) .. : go upward a folder level
cd / : go to root directory
cd ~ : go to home directory
cd - : go to the previous directory
ls :  list directory contents (only name)
ls -l: list all files in directory and detail information of each file
pwd: show directory link, location
mkdir FOLDER: create a new folder
mv: move file or folder
rm FILE: remove files
rm -r FOLDER: remove folder
rmdir: remove empty directories




sed: stream editor for filtering and transforming text
sed -i 's/old/new/g' /home/Directory/File.txt
grep/ egrep/ fgrep: print lines matching a pattern
grep -c 'Error' ../Folder/file.txt :  find the word 'Error' in the file
grep -r -H 'Text' .    find Text in all files in curent folder/subfolder
grep -r -H 'Text' Path    find Text in all files in the directory path
grep -ri 'text' Path    find text ignore case in all files in the directory path
grep -ri -l 'text' Path    find text ignore case in all files in the directory path, and only show the file and location
egrep -w -R "text-1|text-2” Path    find two text
find: search for files in a directory hierarchy
find . -name 'SeachFile*': search file/folder with the beginning text in current directory and all subdirectories (.), exact text & capital
find / -name 'SeachFile': search file/folder with the text in root file system, exact text & capital
find . -iname '*Text*': search file/folder with the beginning text in current directory and all subdirectories (.), only text no matter capital or not
find Direc/file -type f -print0 | xargs -0 grep -l "Text" 

unzip FOLDER.zip  : extract *.zip
tar -xvf FOLDER.tar  : extract *.tar
tar -xvzf FOLDER.tar.gz :  extract *.tar.gz
tar jxvf FOLDER.tar.bz2 : extract *.tar.bz2

zip -r FOLDER.zip FOLDER: compress *.zip
tar -zcvf FOLDER.tar.gz /home/user/Folder   : compress *.tar.gz

ps -ax | grep vim :  find and show all running vim application and their IDs
kill ID:  terminate a process
killall APPLICATION_NAME :  kill processes with specified name
top: display linux tasks
checkjob JOBID: view detail of a task
chmod: change file permission

more : file perusal filter for crt viewing, forward
less:  allows backward movement in the file as well as forward movement
tail: view the last part of files
tail -f: (follow) output appended data as the file grows
head: view the beginning part of files
diff: compare files, show different lines


wc :  print the number of lines, words, and bytes in files
wc -l filename.txt :  print the number of lines in a file
wc -w filename.txt :  print the number of words in a file
sed -n '$=' filename.txt   print number of line
vim -f filename.txt : edit and show total number of lines


gedit:  text editor for the GNOME Desktop
vim/vi: Vi IMproved, a programmers text editor directly on the terminal
cat:     concatenate files and print on the standard output
emacs   text editor
sudo apt-add-repository universe: enable repositories
sudo add-apt-repository ppa:texlive-backports/ppa: add texlive-backports to ppa repository
/etc/apt/sources.list  PPAs

netstat -anp | grep 27000  search all running TCP port number

Tool/Utilities
sudo apt-get install imagemagick  screen capture

gcc: compiler g++
gdb: debugger  

Install Softwares
sudo apt-get update  update all softwares
sudo apt-get upgrade:  upgrade all configuration
sudo dpkg -i filename.deb : install .deb extension file
sudo apt-get install  SOFTNAME: install a software
sudo apt-get remove --purge SOFTNAME: uninstall a software
sudo apt-get autoremove :  auto remove the used, obsolete or repeat software
sudo apt-get install unzip: install unzip
sudo apt-get install default-jdk : Install Java
sudo apt-get install texlive-full: install texlive
sudo apt-get install texmaker: install texmaker


Programming
cmake --version  version of a tool
make -k all
g++ -g -o main main.o:  compile C++
g++ -c -g main.cpp:  compile C++ file "main.cpp"
f77 -o file file.f    : compile the file
./file   : to run and execute the compiled file
sudo apt-get install subversion : Install the Subversion project
sudo apt-get install autoconf:  Install  Autoconf, an extensible package of M4 macros that produce shell scripts to automatically configure software source code packages
sudo apt-get install automake:            Install Automake is a tool for automatically generating Makefile.in files compliant with the GNU Coding Standards
sudo apt-get install libtool:           Install GNU libtool is a generic library support script.
sudo apt-get install gfortran :      Install gfortran compiler
sudo apt-get install gfortran gfortran-4.6 libgfortran3 gfortran-multilib gfortran-doc gfortran-4.6-multilib gfortran-4.6-doc libgfortran3-dbg
sudo apt-get install g77 :             Install fortran 77 compiler
apt-get install build-essential
apt-get install gcc-multilib
apt-get install rpm

g++ main.o word.o hello.o -o hello


Remote control/ access server/ connect through ssh
sudo apt-get install openssh-server      install openssh in the server
ssh <username>@<computer name or IP address>
ssh me@homecomputer
ssh me@172.121.5.1  or ssh-v me@172.121.5.1
ps aux | grep sshd                    to check whether ssh is running in the server
sudo more /var/log/auth.log    on the server

Create a software shortcut on desktop
sudo apt-get install --no-install-recommends gnome-panel
gnome-desktop-item-edit ~/Desktop/ --create-new
Name: Application name
Command:  link to the application location

No comments:

Post a Comment