Created
March 12, 2016 21:43
-
-
Save marinsagovac/a8f9e80fc92bcd4373d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Allow a command to continue execution after logout | |
nohup mycommand & | |
# Display one particular line from a file | |
gzip -dc mytarball.tar.gz | tar xvf - | |
# Display current runlevel | |
who -r | |
# Split lines of text into n-char lines | |
echo "some line of chars" | fold -w 3 | |
# Insert spaces at beginning of each line in vi | |
:5,16s/^/ / # for lines 5 through 16, for example | |
# Display last 10 system reboots | |
last reboot | head | |
# Check which processes are listening on which ports | |
lsof -i | grep LISTEN | |
# Print range of lines from a file | |
sed -n '100,200 p' filename | |
# Move last file modified | |
mv `ls -1 -t *.txt | head -1` whatever.txt | |
# Bourne-type shells: Find a file’s hard links | |
inode=`ls -li /path/and/filename | awk '{print $1}'` | |
find / -inum $inode -exec ls -li {} \; | |
# Sybase – Check status of databases | |
# su - sybase | |
Password: | |
> isql -Usa -Ppassword -w200 | |
1> use master | |
2> go | |
1> select status, name from sysdatabases | |
2> go | |
# Convert single column into two columns line by line | |
$ cat foofile | |
a | |
b | |
c | |
d | |
e | |
f | |
$ paste -d: - - < foofile | |
a:b | |
c:d | |
e:f | |
# gunzip and untar with one pipe | |
gzip -dc SOMEFILE.tar.gz | tar xvf - | |
# or with GNU tar | |
tar xvzf SOMEFILE.tar.gz | |
# Quickly copy a directory tree with tar | |
cd /path/to/source | |
tar cvf - ./* | ( cd /dest; tar xvf - ) | |
# Access the local shell from an ftp session | |
# note - this depends on your ftp client | |
ftp> ! | |
$ echo "Now in local shell" | |
# iconv convert between codesets | |
iconv -f UTF-8 -t iso85591 somefile | |
# recursively change permissions on directories only | |
find . -type d -exec chmod 755 {} \; -print 2>/dev/null | |
# set MTU value for an interface | |
ifconfig interface mtu n | |
# e.g. | |
ifconfig hme0 mtu 1500 | |
# place in hostname.interface file for persistence | |
# ping using alternative interface | |
ping -i bge1 somehost | |
# shutdown your system | |
init 0 | |
shutdown -h now | |
# reboot | |
init 6 | |
shutdown -r now | |
# make a file immutable | |
chattr +i somefile | |
# show inode information for all files in a directory | |
find . -type f -exec stat {} \; | |
# Linux screenshots | |
xwd -display servername:0 -root > myfile.dmp | |
xwd | xwud | |
# perform a reverse DNS lookup | |
host xxx.xxx.xxx.xxx dns_server_ip | |
# check mouse is operational | |
cat /dev/mouse # then move the mouse | |
# is SELinux enabled? | |
selinuxenabled && echo Yes | |
# or | |
# getenforce | |
Enforcing | |
# Display SELinux context in ls listings | |
ls -lZ /some/dir | |
# tcpdump port 123 (ntp) | |
tcpdump port 123 | |
# disable HTTP TRACE in apache | |
# vi /etc/httpd/conf/httpd.conf | |
# grep Rewrite /etc/httpd/conf/httpd.conf | |
RewriteEngine On | |
RewriteCond %{REQUEST_METHOD} ^TRACE | |
RewriteRule .* - [F] | |
# apachectl restart | |
# check TCPD rules in /etc/hosts.{allow,deny} | |
grep -v "^#" /etc/hosts.allow /etc/hosts.deny | grep -v "^[ ]*$" | |
# common vi(m) options | |
# ignore case | |
:set ic | |
# line numbers | |
:set num | |
:set nonum | |
# turn off search highlighting (VIM) | |
:nohl | |
# syntax highlight on (VIM) | |
:sy on | |
# show unprintable characters | |
:set list | |
# remove files older than one week | |
/usr/bin/find /some/dir -name "*whatever*" -mtime +7 | xargs rm | |
# find world writable files | |
/usr/bin/find / -perm -0777 -exec /usr/bin/ls -ld {} \; | |
# symbolic links will always be 77 so we can ignore them | |
/usr/bin/find -perm -0777 ! -type l -exec /usr/bin/ls -ld {} \; | |
# gzip and tar in one line | |
tar cvf - ./* | gzip -c > foo.tar.gz | |
# untar | |
tar xzvf foo.tar.gz | |
# find ip address for an interface | |
/sbin/ifconfig interface | grep inet | |
# e.g. | |
/sbin/ifconfig bge0 | grep inet | |
# filename completion ksh (vi mode) | |
ESC-\ | |
# bourne based shells – show current environment variables | |
env | |
# show all variables | |
set | |
# show shell options | |
set -o | |
# current shell options (set via set -x, etc) | |
echo $- | |
# bash | |
shopt | |
# show current shell | |
echo $0 | |
# stop people logging in | |
touch /etc/nologin | |
# sed to replace \ with \\ | |
sed -e 's_\\_\\\\_g' | |
# recursive grep | |
find . -type f -exec grep "somestring" {} /dev/null \; | |
# show subdirectories only in an ls listing | |
ls -l | grep "^d" | |
# recursively | |
find . -type d -exec ls -ld {} \; | |
# create soft link | |
ln -s file_to_link link_name | |
# hard link | |
ln file_to_link link_name | |
# searching for a literal $ in a file | |
grep '\$' filename | |
# or fgrep / grep -F | |
fgrep '$' filename | |
# correct permissions on /tmp and /var/tmp | |
chmod 1777 /var/tmp | |
# or | |
chmod a=rwx,+t /var/tmp | |
# display unprintable filenames | |
ls -lb somedir | |
# find files larger than 300k | |
find / -size +300k -ls 2> /dev/null | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment