Skip to content

Instantly share code, notes, and snippets.

@hvan021
Last active August 29, 2015 14:01
Show Gist options
  • Save hvan021/6f853a2e5ad288b43906 to your computer and use it in GitHub Desktop.
Save hvan021/6f853a2e5ad288b43906 to your computer and use it in GitHub Desktop.

HARDWARE

uname -a

lscpu or cat /proc/cpuinfo

lspci

SHELL KEYBOARD SHORTCUT

see here for more https://wiki.archlinux.org/index.php/Keyboard_Shortcuts

Ctrl+t Ctrl+r

Ctrl+X then Ctrl+E

command ESC. command !$ command !*

Ctrl+w Ctrl+u Ctrl+k Esc+d Alt+d Alt+Ctrl+y Paste the first argument of the previous command Alt+. or Alt+_

cd - >>> move back to last dir

^wrong_command^command

SHELL SCRIPT

make new user script >>>>> create_user

#!/bin/bash
useradd -m $1
passwd $1
mkdir -p /shared/$1
chown $1:users /shared/$1
chmod 755 /shared/$1
ln -s /shared/$1 /home/$1/shared
chown /home/$1/shared

ping /test default gateway >>> router_check####

#!/bin/bash
ip = `route -n | grep UG | tr -s " " |  cut -f 2 -d " " `
ping = "/bin/ping"
echo "testing gateway @ $ip by pinging 5 times"
ping -c 5 $ip

interactive user creation shell script ####

#!/bin/bash
echo -n "Enter user name:"
read name
useradd -m $name
passwd $name
.....


#!/bin/bash

if [-s /var/apache2/log]
    then 
        tail /var/apache2/log
        exit
fi

OR

if test -s /var/apache2/log
    then 
        tail /var/apache2/log
        exit
fi



#!/bin/bash
for d  in `ls *.wav`; do
    aplay $d
done


#!/bin/bash
doit(){
    cp $1 $2
}

function check(){
    if [ -s $2]
        then echo "target file exists"
        exit
    fi
}


check $1 $2
doit $1 $2

FILES

touch -d "April  13 xxx" file.txt

touch -t 20140215hhmm file.txt


ln -s origname linkname


mkdir

rmdir
rmdir -p parentdir/childdir   >>>>> remove both dirs

HELP

whatis
man

/pattern  >>>> search forward
?pattern  >>>> search backward

n or / repeat search


info

PROGRAM & PROCESS

yum /apt-get
apt-get [install/update/upgrade/remove/purge]


ps u
ps ax | less
ps aux



top
top -M

free


ll /var/log
dmesg | less

SEARCHING >

>>
2>
2>>
&> create new file containing both standard and error output

<
<<
<> both ways

GENERATING COMMAND LINE

xargs [options]      [command     [initial-args]  ]

Example:
find ./ -name "*~" |  xargs rm

rm `find ./ -name "*~"`

EXTRACTING/ARCHIVING

tar cvfz target_file.tgz    ~/source_file

tar xvfz file.tgz

USER

who
w
getent passwd
cat /etc/passwd
cat /etc/shadow
cat /etc/group

PERMISSION

chgrp
chown
chmod
sticky bit + special permission

NETWORK

ifconfig
ifconfig eth0 up [ip] netmak 255.255.255.0\

host

route
route add defaut gw [gateway ip]
traceroute

 ll /etc/network/interfaces
cat /etc/resolv.conf

netstat -i

netstat -a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment