• crontab -l //list crontab

  • crontab -r //remove crontab

  • crontab -e //edit crontab

    • minute hour day-of-month month day-of-week cmd
    • each term can be a single number, e.g., 3, or a range, e.g., 3-6, or a set, e.g., 3,5,7, or interval, e.g., */10
    • for example, “ /10 * sh ~/cmd.sh” means executing cmd.sh every 10 minutes.

In windows, the function of contrab can be realized by using “task scheduler”.

Here is a website link to query linux commands.


  1. create new user with home folder

    1
    adduser XXX
  2. sudo privilege: vim /etc/sudoers and add $username ALL=(ALL) ALL at the bottom.

  3. start ssh on the server, the default port is 22

    1
    2
    sudo apt-get install openssh-server
    sudo/etc/init.d/ssh start
  4. list

    1
    2
    3
    list -a #including hidden files
    list -S #arrange by size
    list -t #arrange by time
  5. view text

    1
    2
    3
    cat
    head/tail -n 10 tmp.txt #view the first/last 10 lines
    less #more powerful than more
  6. Change the privilege

    1
    2
    chmod 777 ./
    chmod a+x ./
  7. Check disk or file size

    1
    2
    df -h 
    du ./ --max-depth 2 -h
  8. Compress or uncompress files, refer to this link.

  9. Grep + regular expression

    1
    grep [xyz]
  10. Search file

    1
    2
    3
    4
    5
    locate "keyword" #fast
    find ./ -maxdepth 1 -name "*keyword*"
    find ./ -name "*keyword*" -size +50M -size -100M
    find ./ -name "*keyword*" -mmin -10 #m:modify min:minute
    find ./ -name "*keyword*" -exec rm -r {} \;
  11. Pipe commands

    1
    2
    3
    ls -l | tr -s ' ' | cut -d ' ' -f 2 #tr to truncate space
    ls -l | sort -rnk2 #-r:reverse -n:numerical -k:k-th column
    ls -l | wc -l #count line
  12. xargs:

    1
    2
    3
    cat python/requirements.txt | xargs -L 1 sudo pip install
    find . -name "*.c" | xargs rm -rf
    find . -name '*.c' | xargs grep 'stdlib.h'
  13. alias: temporary alias command

    1
    2
    alias lnew="cd /home/niuli/caffe"
    unalias lnew
  14. export: The export command is one of the bash shell built-in commands, which means it is part of your shell.

    1
    2
    3
    4
    5
    6
    export a=linux.com
    echo $a
    export -n a #remove variable

    printname () { echo "Linuxcareer.com"; }
    export -f printname #export function

    add LD_LIBRARY_PATH

    1
    2
    echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda/lib64:/usr/local/lib' >> ~/.bashrc
    source ~/.bashrc
  15. shellscript sample

    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
    #!/bin/bash
    read -p "Please input your first name: "
    echo -e "\nYour full name is: $firstname $lastname"
    test ! -e $filename && echo "The filename '$filename' DO NOT exist" && exit 0
    test -f $filename && filetype="regulare file"
    test -d $filename && filetype="directory"
    [ "$yn" == "Y" -o "$yn" == "y" ] && echo "OK, continue" && exit 0

    if [ "$yn" == "Y" ] || [ "$yn" == "y" ]; then
    echo "OK, continue"
    elif [ "$yn" == "N" ] || [ "$yn" == "n" ]; then
    echo "Oh, interrupt!"
    else
    echo "I don't know what your choice is"
    fi

    while [ "$yn" != "yes" -a "$yn" != "YES" ]
    do
    read -p "Please input yes/YES to stop this program: " yn
    done

    for animal in dog cat elephant
    do
    echo "There are ${animal}s.... "
    done

  1. zip/unzip

    winrar x -y -ibck zip_file_name unzip_file_name //x means unzip, -y means yes to interrupted queries, -ibck means running in the background

  2. generate the file list under one folder

    dir D:\test /b >list.txt or dir D:\test /b >list.xls

  3. combine multiple compressed volumes

    copy /b logs.tar.gza* logs.tar.gz

First check whether the file system is MBR+BIOS or GPT+UEFI. Nowadays, most computers are GPT+UEFI, so we only talk about GPT+UEFI here.

  1. Download Ubuntu iso and make a U-installer using rufus. When using rufus, notice the option of GPT+UEFI.

  2. Start the computer from U-installer. The most important thing is making a proper partition for Ubuntu. At least make three partitions: / (ext4), swap (2G), reserved for UEFI (1G). If necessary, make another partition /home. Note that ubuntu UEFI should be on the same disk as Windows UEFI.

If something is wrong when attempting to enter the BIOS, try the following approaches:

  • press F2, F12, ESC, DEL
  • change the cable, adaptor, interface, etc (hardware reason)
  • update BIOS to the latest version
  • for Windows10, settings->recover->firmware
  • close fast-boot option in the operation system because fast-boot may directly skip the BIOS stage

Sometimes Ubuntu fails to connect VPN. Open the PPTP advanced options, uncheck EAP and check MPPE.

Server:

  1. Install VNC server under Ubuntu: $sudo apt-get install vnc4server

  2. Configure the VNC server, $vi ~/.vnc/xstartup
    change the style to gnome-session & in the last line.

  3. start the VNC server: $vncserver

Client:

  1. Install VNC client under Windows: use http:\IP:580$ID to log in.

Tips: For 10060 error, run $iptables -F to close firewall.

Server:

  1. run $sudo apt-get install openssh-server

  2. run $ps -A |grep ssh.
    If there is sshd, then ssh-server has been started,
    else run $sudo /etc/init.d/ssh start to start ssh-server.

Tips: To stop ssh-server, execute $sudo /etc/init.d/ssh stop.
To modify the configuration, edit /etc/ssh/sshd_config.

Client:

ssh-client is usually already installed. If not, run
$sudo apt-get install openssh-client.

After installing ssh-client, run $ssh username@192.168.1.112.

Mount Linux folder under Linux

1
2
sudo apt-get install cifs-utils
sudo mount -t cifs -o username=XXX,password=XXX //10.70.1.82/src_dir tgt_dir

Mount Windows folder under Windows

add network device

Mount Linux folder under Windows


  1. Install Dokan and WinSSHFS: for Win10, recommend 1.6.1.13 win-sshfs and 1.0.3 Dokan.

  2. Open WinSSHFS, fill in the drive name, host, port, username, password, directory. The other entries can be left blank.

Remote Connect to Ubuntu in Windows


a) cmdline: putty, secureCRT

b) window:

xrdp: http://jingyan.baidu.com/article/8ebacdf0cdc64949f75cd555.html

1
2
3
4
5
sudo apt-get install xrdp
sudo apt-get install vnc4server
sudo apt-get install xubuntu-desktop
echo "xfce4-session" >~/.xsession
sudo service xrdp restart

xrdp mm process login response login failed
When this error occurs, try the following methods, followed by “sudo service xrdp restart”.

  1. delete vnc processes

    1
    2
    ps -ef | grep vnc
    kill -9 XXX
  2. delete X sessions, .xrdp, .X11-unix, .X0-20

    1
    cd /tmp && ls -a
  3. modify “MaxSessions” number

     sudo vim /etc/xrdp/sesman.ini
    
0%