Author Topic: unix commands i'd like to remember  (Read 3354 times)

0 Members and 1 Guest are viewing this topic.

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
unix commands i'd like to remember
« on: March 30, 2013, 04:23:43 am »
0
some stuff i forget, going to put it here.. isUseful().

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #1 on: March 30, 2013, 04:25:01 am »
0
tac => reverse read files
nl => prepend line numbers
shuf => shuffle data
comm => compare sorted files
base64
pr => paginate text/data
paste <file1> <fileN> ... => concat multiple files into a table of columns

ptx!

Code: [Select]
cat /etc/motd|ptx

         Debian GNU/Linux comes with   ABSOLUTELY NO WARRANTY, to the/
     /The programs included with the   Debian GNU/Linux system are free/
   ABSOLUTELY NO WARRANTY, to/         Debian GNU/Linux comes with
   ;/      /included with the Debian   GNU/Linux system are free software
   WARRANTY, to the/          Debian   GNU/Linux comes with ABSOLUTELY NO
   Sun Sep 23 10:07:46 UTC 201/        Linux serv 2.6.32-5-amd64 #1 SMP
      /included with the Debian GNU/   Linux system are free software;/
   WARRANTY, to the/     Debian GNU/   Linux comes with ABSOLUTELY NO
    /GNU/Linux comes with ABSOLUTELY   NO WARRANTY, to the extent/
        Linux serv 2.6.32-5-amd64 #1   SMP Sun Sep 23 10:07:46 UTC 2012 x/
     /serv 2.6.32-5-amd64 #1 SMP Sun   Sep 23 10:07:46 UTC 2012 x86_64/
   4/    /serv 2.6.32-5-amd64 #1 SMP   Sun Sep 23 10:07:46 UTC 2012 x86_6
    /Sep 23 10:07:46 UTC 2012 x86_64   The programs included with the/
      /64 #1 SMP Sun Sep 23 10:07:46   UTC 2012 x86_64  The programs/
    //Linux comes with ABSOLUTELY NO   WARRANTY, to the extent permitted/
   UTC 201/     Linux serv 2.6.32-5-   amd64 #1 SMP Sun Sep 23 10:07:46
        , to the extent permitted by   applicable law.         /NO WARRANTY
        /the Debian GNU/Linux system   are free software; the exact/
   files/    /terms for each program   are described in the individual
           , to the extent permitted   by applicable law.      /NO WARRANTY
   to the/          Debian GNU/Linux   comes with ABSOLUTELY NO WARRANTY,
          files in /usr/share/doc/*/   copyright.        /in the individual
         /terms for each program are   described in the individual files/
       /are free software; the exact   distribution terms for each/
     individual files in /usr/share/   doc/*/copyright.             /in the
       /exact distribution terms for   each program are described in the/
      /system are free software; the   exact distribution terms for each/
     /ABSOLUTELY NO WARRANTY, to the   extent permitted by applicable law/
    /are described in the individual   files in /usr/share/doc/*//
     /; the exact distribution terms   for each program are described in/
     the Debian GNU/Linux system are   free software; the exact/      /with
     /for each program are described   in the individual files in /usr//
            /in the individual files   in /usr/share/doc/*/copyright.
    /6 UTC 2012 x86_64  The programs   included with the Debian GNU/Linux/

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #2 on: April 28, 2013, 05:30:05 pm »
0
rpm --import GPG-KEY-FILE
rpm -qa
rpm --checksig -v package.rpm
rpm -K package.rpm

apt-key list
apt-get install debian-archive-keyring
gpg --import file.key
gpg --export -armor XXX | apt-key add

apt-cache depends package
dpkg -L package
dpkg -l

linux kern recomp:
if built before: make mrproper
2.4:
make config, make oldconfig, make menuconfig, make xconfig,
make dep
make bzImage
make modules
make modules_install
cp arch/i386/boot/bzImage b/boot/vmlinuz-2.4.0
cp System.map /boot/System.map-2.4.0
for lilo: edit /etc/lillo.conf
for grub: edit /boot/grub/menu.lst

if need initrd image, cd /boot; mkinitrd

2.6:
devfs now obsolete in favor of udev
make clean mrproper
make menuconfig
make dep
make bzImage
make modules
make modules_install
cp arch/i386/boot/bzImage /boot/vmlinuz-2.6.x.img
make install
if using initramfs image: update-initramfs -c -k 'version'

2.6 debian:
need: kernel-package, ncurses-dev, fakeroot, wget, bzip2
apt-get install linux-source-2.6.x
tar xvjf /usr/src/linux-source*
apt-get install build-essential fakeroot
apt-get build-dep linux-source-2.6.x
cd /usr/src/linux-source*
fakeroot debian/rules binary
make menuconfig
make-kpkg clean
fakeroot make-kpkg --initrd --revision=custom.1.0 kernel_image
dpkg -i ../linux-image-*.deb


patch -p1 < kern.patch

depmod <module>, list dependencies


yum install kernel kernel-source


some differences:

fedora:
/etc/alternatives -> if there is more than one equiv program present for a specific task, must be listed here
/etc/profile.d -> files that are executed when a user opens a shell
/etc/sysconfig -> configuration data for various aspects of the system
/etc/cron -> cron
/etc/pam.d -> pam files
/etc/logrotate.d -> log rotation configuration

kudzu -> exames hardware at startup


debian:
dpkg, apt-get, dselect, tasksel
/etc/default -> configuration defaults
/etc/network -> ya
/etc/dpkg and /etc/pt -> info on configuration management tools

to reconfigure a package:

dpkg-reconfigure x-window-system



/etc/init.d -> stores startup scripts

"a run level is basically a configuration of programs and services that will be executed in order to carry out determined tasks"
0 -> halt
1 -> single user mode
2 -> multi user without network
3 -> multi user
4 -> multi user (same as 3)
5 -> multi user x -> multi user with X support
6 -> reboot

debian -> run levels 2 through 5 are the same
- default run level is 2



telinit : changes run level, telinit <number>

debian:
update-rc.d -> install or delete startup services

cat /proc/cmdline
cat /proc/meminfo
cat /proc/ioports

/dev/hdaX IDE
/dev/sdaX SCSI

/etc/skel - files copied to user directory upon adduser
usermod, modify user

"we can check whether we are in a NIS env by seeing if 'compat' appears in the passwd line and group configuration file, /etc/nsswitch.conf"

yppasswd, nispasswd


lpr: bsd
lp: sysv

BSD, LPRng, CUPS

lpr, lprm, lpq

BSD LPD: /etc/printcap, /etc/hosts.lpd

CUPS: /etc/cups

badblocks -> find bad blocks
dumpe2fs -> dump fs info
tune2fs -> file system tuning, acl's etc

RAID -> all disks in array must have same size
RAID 0 - data is distributed equally among the raid disks
RAID 1 - data is mirrored, exact copy, on the other raid disks, 24/7, high availability, can hot swap

md - multi device driver, can incorporate raid etc
mdadm -> create raid devices

LVM2 based on hp-ux


LVM2
physical volumes: PV anything that appears as a hard disk to the system
logical volumes: LV equivalent to a partition on a physical disk., appear as physical devices
volume groups: V this is the administrative unit, upper layer,

up2date - redhat update

nohup - keep processes running even if log out

at 5:05pm

/etc/crontab
* = whichever

# * * * * * command to be executed
# - - - - -
# | | | | |
# | | | | +- - - - day of week (0 - 6) (Sunday=0)
# | | | +- - - - - month (1 - 12)
# | | +- - - - - - day of month (1 - 31)
# | +- - - - - - - hour (0 - 23)
# +- - - - - - - - minute (0 - 59)

# Alarm clock set to 6:30AM
30 6 * * * /home/nano/alarm

cron.allow, cron.deny
/var/spool/cron



load avg: 1min, 5min, 15min


analysis of box initial:
uptime
dmesg
tail 200 /var/log/messages
lsmod
ps -ef
free -m
vmstat




kswapd: controls virtual memory swaps
bdflush: handles system buffers
kjournald: handles journal fs
khubd: usb handling
udev:

.*d = daemon
.*k = kernel thra


ip6tables

slapd - ldap
ldapadd, ldap browser
slapadd

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #3 on: July 10, 2013, 09:04:34 pm »
0
$ sed -e 's/\(.JPG*\)/\L\1/' in > out

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #4 on: July 12, 2013, 12:11:28 am »
0
find . -newermt "2013-01-01 00:00:00" ! -newermt "2013-01-02 00:00:00"

rsync -a --files-from=list . dst

find a | xargs -I{} cp -t "{}" dst

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #5 on: July 19, 2013, 04:12:00 pm »
0
hdparm -t /dev/bleh:

Code: [Select]
/dev/sda1:
Timing buffered disk reads: 458 MB in  3.01 seconds = 152.38 MB/sec
root@ubuntu:/home/adarqui# hdparm -t /dev/sdb1

/dev/sdb1:
Timing buffered disk reads: 916 MB in  3.00 seconds = 305.05 MB/sec



temperature ubuntu:

Code: [Select]
apt-get install lm-sensors
modprobe coretemp

sensors

coretemp-isa-0000
Adapter: ISA adapter
Physical id 0:  +47.0°C  (high = +87.0°C, crit = +97.0°C)
Core 0:         +45.0°C  (high = +87.0°C, crit = +97.0°C)
Core 1:         +43.0°C  (high = +87.0°C, crit = +97.0°C)
Core 2:         +42.0°C  (high = +87.0°C, crit = +97.0°C)
Core 3:         +47.0°C  (high = +87.0°C, crit = +97.0°C)

coretemp-isa-0001
Adapter: ISA adapter
Physical id 1:  +41.0°C  (high = +87.0°C, crit = +97.0°C)
Core 0:         +39.0°C  (high = +87.0°C, crit = +97.0°C)
Core 1:         +38.0°C  (high = +87.0°C, crit = +97.0°C)
Core 2:         +40.0°C  (high = +87.0°C, crit = +97.0°C)
Core 3:         +39.0°C  (high = +87.0°C, crit = +97.0°C)

coretemp-isa-0002
Adapter: ISA adapter
Physical id 2:  +44.0°C  (high = +87.0°C, crit = +97.0°C)
Core 0:         +41.0°C  (high = +87.0°C, crit = +97.0°C)
Core 1:         +44.0°C  (high = +87.0°C, crit = +97.0°C)
Core 2:         +43.0°C  (high = +87.0°C, crit = +97.0°C)
Core 3:         +43.0°C  (high = +87.0°C, crit = +97.0°C)

coretemp-isa-0003
Adapter: ISA adapter
Physical id 3:  +48.0°C  (high = +87.0°C, crit = +97.0°C)
Core 0:         +48.0°C  (high = +87.0°C, crit = +97.0°C)
Core 1:         +48.0°C  (high = +87.0°C, crit = +97.0°C)
Core 2:         +45.0°C  (high = +87.0°C, crit = +97.0°C)
Core 3:         +48.0°C  (high = +87.0°C, crit = +97.0°C)

T0ddday

  • Hero Member
  • *****
  • Posts: 1343
  • Respect: +1114
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #6 on: July 19, 2013, 04:45:45 pm »
0
The package manager stuff I constantly forget.  But as far as the file operations I recommend just getting really good at awk.  I didn't know that prepend line number command, but I know awk and a bit of sed so I can work on filestreams and do 99% of what I need to do with awk.  Prepending line numbers in awk would just be " awk '{print NR,$0}'  File.txt > File.out "

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #7 on: July 19, 2013, 08:02:31 pm »
0
kewl ya i love awk.

for line numbers,u can do nl <filename> or cat file | nl etc.. that's a quick shortcut too.

pC









http://askubuntu.com/questions/105040/how-do-i-force-a-user-to-change-the-password-periodically

Code: [Select]
chage -l user
password -xdays user

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #8 on: July 20, 2013, 12:37:15 am »
0
http://en.positon.org/post/Rsync-command-restriction-over-SSH

Code: [Select]
command="rsync --server --sender -vlogDtprze.iLsf --numeric-ids . /path/" ssh-rsa AAAAB3NzaC1in2EAAAABIwAAABio......



runlevel manual, for chroot:

Code: [Select]
/etc/init.d/rc 2

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #9 on: July 22, 2013, 02:37:02 am »
0
Code: [Select]
pstree -p


find . ! -size 0

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #10 on: July 23, 2013, 01:46:00 am »
0
ps afx

Code: [Select]
1389 pts/0    S+     0:00                          \_ screen
 1390 ?        Ss     0:07                              \_ SCREEN
 1391 pts/1    Ss     0:00                                  \_ /bin/bash
 5054 pts/1    S+     0:00                                  |   \_ lxc-start -n app
 5059 ?        Ss     0:00                                  |       \_ /sbin/init
 5216 ?        S      0:00                                  |           \_ upstart-udev-bridge --daemon
 5223 ?        Ss     0:00                                  |           \_ dbus-daemon --system --fork --activation=upstart
 5226 ?        Ss     0:00                                  |           \_ /sbin/udevd --daemon
 6402 ?        S      0:00                                  |           |   \_ /sbin/udevd --daemon
 5232 ?        Sl     0:00                                  |           \_ rsyslogd -c5
 5396 ?        S      0:00                                  |           \_ upstart-socket-bridge --daemon
 5484 ?        Ss     0:00                                  |           \_ dhclient3 -e IF_METRIC=100 -pf /var/run/dhclient.eth0.pid -lf /var/lib/dhcp/dhclient.eth0.leases -1 eth0
 5511 ?        Ss     0:00                                  |           \_ /usr/sbin/sshd -D
 5573 pts/5    Ss+    0:00                                  |           \_ /sbin/getty -8 38400 tty4
 5585 pts/3    Ss+    0:00                                  |           \_ /sbin/getty -8 38400 tty2
 5586 pts/4    Ss+    0:00                                  |           \_ /sbin/getty -8 38400 tty3
 5587 ?        Ss     0:00                                  |           \_ nginx: master process /usr/sbin/nginx -c /etc/nginx/nginx.conf
 5592 ?        S      0:00                                  |           |   \_ nginx: worker process                   
 5593 ?        S      0:00                                  |           |   \_ nginx: worker process                   
 5594 ?        S      0:00                                  |           |   \_ nginx: worker process                   
 5595 ?        S      0:00                                  |           |   \_ nginx: worker process                   
 5599 ?        Ss     0:00                                  |           \_ cron
 5600 ?        Ss     0:00                                  |           \_ atd
 5601 ?        Ss     0:00                                  |           \_ acpid -c /etc/acpi/events -s /var/run/acpid.socket
 5615 ?        Ssl    0:00                                  |           \_ whoopsie
 5624 ?        Ssl    0:01                                  |           \_ /usr/sbin/mysqld
 5662 ?        Ss     0:00                                  |           \_ php-fpm: master process (/etc/php5/fpm/php-fpm.conf)     
 6446 ?        S      0:03                                  |           |   \_ php-fpm: pool www                                         
 6457 ?        S      0:04                                  |           |   \_ php-fpm: pool www                                         
 6460 ?        S      0:04                                  |           |   \_ php-fpm: pool www                                       

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #11 on: July 23, 2013, 03:16:54 am »
0
grep -F for pure strings

Code: [Select]
while read line ; do grep -F "$line" list.s3 ; done < base.sdiff > base.sdiff.s3

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #12 on: July 23, 2013, 09:45:17 pm »
0
http://www.madboa.com/geek/openssl/


re-encoding certs for aws cloudfront:
Code: [Select]
openssl rsa -in cert.key -text > rsa.what
copy the outputted key to rsa.key:  vim rsa.key
openssl x509 -inform PEM -in cert.crt > rsa.crt
iam-servercertupload -v -b rsa.crt  -k rsa.key -s realtime-cert



Code: [Select]
openssl req -in cert.csr -noout -text

openssl req -in cert.csr -noout -verify -key cert.key

openssl x509 -text -in key.crt

openssl rsa -in key.key -pubout


#!/bin/sh
#
# usage: retrieve-cert.sh remote.host.name [port]
#
REMHOST=$1
REMPORT=${2:-443}

echo |\
openssl s_client -connect ${REMHOST}:${REMPORT} 2>&1 |\
sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'



http://superuser.com/questions/73979/how-to-easily-create-a-ssl-certificate-and-configure-it-in-apache2-in-mac-os-x


Code: [Select]
openssl s_client -showcerts -connect wanet:443 | less






SSL
http://www.sslshopper.com/article-most-common-openssl-commands.html

Code: [Select]
openssl req -out CSR.csr -new -newkey rsa:2048 -nodes -keyout privateKey.key



signing a csr with existing key:
Code: [Select]
openssl req -new -key key.pem -out req.pem

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #13 on: July 26, 2013, 12:10:28 pm »
0
ntp update immediately:

service ntp stop ; ntpdate pool.ntp.org ; service ntp start

adarqui

  • Administrator
  • Hero Member
  • *****
  • Posts: 30918
  • who run it.
  • Respect: +7590
    • View Profile
    • Email
Re: unix commands i'd like to remember
« Reply #14 on: July 26, 2013, 03:47:04 pm »
0
watch -n1 -d=cumulative ls -al /etc/nginx/logs/