Using touch command

Read More

touch Creates a file without content

touch file_name

For multiple files

touch File_name1 File2_name2 File_name3

Running touch on an already existing file: the file’s access and modification timestamps are updated to the current time, the content is not modified

touch -a To modify the access time only

touch -a file_name

touch -am Change access and modification time together

touch -am file_name

touch -c To check if file is created or not

touch -c file_name

-d option Use string with date instead of current time
touch -c -d "2020-03-09 11:33:12.000000000 +0100" file_name
-t option Use timestamp instead of current time. Format [[CC]YY]MMDDhhmm[.ss] touch -c -t 202003091133 file_name

touch -m This is used to change the modification time only
touch -m file_name

touch -r This command is used to copy only the timestamp onto another file

touch -r reference_file_name target_file_name

touch -h For modifying a symbolic link, not the pointed to

touch -h symbolic_link_file

Create several files touch

# Create files with names A to Z
$ touch {A..Z}
# Create files with names 1 to 20
$ touch {1..20}
# Create files with extension
$ touch {1..1000}.txt
# Create 10K files
$ touch {1..10}{1..1000}

Using touch to restore timestamps in a directory tree

To change all the directories to 755 (drwxr-xr-x):

find /opt/lampp/htdocs -type d -exec chmod 755 {} \;

To change all the files to 644 (-rw-r–r–):

find /opt/lampp/htdocs -type f -exec chmod 644 {} \;

And to change file and directories timestamp

find . -exec touch {} \;

Only files

find . -type f -exec touch {} \;

User management in Ubuntu

Show last user logins into the system
lastlog | less
Currently logged in users in the system
who

Add new user
adduser username usergroupname (perl calling useradd)
useradd username

Delete user
userdel username
userdel -r username removing home directory

deluser with /etc/deluser.conf (Debian and derivatives)
deluser --remove-home

 

 

Bash Reference

Read More

The Shebang (#!)

  • In the beginning, first line of the file, no spaces.
  • Next, absolute path to the script interpreter (might change, but better to execute anywhere), in this case: /bin/bash
  • Call to the script does not look in current directory, so ./ is necessary or it has to be included in PATH

Special System Variables

  • $0 – The name of the Bash script.
  • $1 – $9 – The first 9 arguments to the Bash script.
  • $# – How many arguments were passed to the Bash script.
  • $@ – All the arguments supplied to the Bash script.
  • $? – The exit status of the most recently run process.
  • $$ – The process ID of the current script.
  • $USER – The username of the user running the script.
  • $HOSTNAME – The hostname of the machine the script is running on.
  • $SECONDS – The number of seconds since the script was started.
  • $RANDOM – Returns a different random number each time is it referred to.
  • $LINENO – Returns the current line number in the Bash script.

Variable Assignment

variable=value

  • No $ sign at the beginning.
  • No space at either side of the equal.
  • Case sensitive.
  • Variables set by a program must not have = or nul, but for the shell environment, they have more limitations: consist solely of uppercase letters, digits, and the ‘_’ (underscore) and do not begin with a digit. User variables follow the C variable definition rules (lowercase allowed). Regex:[a-zA-Z_]+[a-zA-Z0-9_]*

Quotes

Bash uses a space to determine separate items. When we enclose our content in quotes we are indicating to Bash that the contents should be considered as a single item. You may use single quotes ( ‘ ) or double quotes ( ” ).

  • Single quotes will treat every character literally.
  • Double quotes will allow you to do substitution (that is include variables within the setting of the value) nvar="Add $var"

Command Substitution

The output of command or program is saved into a variable variable=$(command) ex. directoryls=$(ls -al)
Adequate for just one word or line, newlines are removed and stored in a single line in the variable.

Exporting Variables

Exporting variables make them available for child subprocesses created in the running script
export var
Note: exporting a variable to the environment only works in the interactive console, not in scripts. To export it, modify /etc/environment from a script

Arithmetic

    • let expression Make a variable equal to an expression. Ex. let a=5+4
    • expr expression Print out the result of the expression.
    • $(( expression )) Return the result of the expression.
    • ${#var} Return the length of the variable var.
Operator Operation
+, -, /*, / addition, subtraction, multiply, divide
var++ Increase the variable var by 1
var– Decrease the variable var by 1
% Modulus (Return the remainder after division)

 

Control Statements

IF
if [ <some test> ] then
<commands>
elif [ <some test> ] then
<different commands>
else
<other commands>
fi

CASE
case <variable> in
<pattern 1>)
<commands>
;;
<pattern 2>)
<other commands>
;;
esac

WHILE

while [ <some test> ] do
<commands>
done

UNTIL

until [ <some test> ] do
<commands>
done

FOR

for var in <list>
do
<commands>
done

SELECT Present list items for selection with a number before each item
select var in <list>
do
<commands>
done

break Goes out of the loop
continue Goes to the beginning of next iteration
Range ex. for value in {1..5}
Range with step ex. for value in {10..0..2}

Operator Description
&& And
|| Or
! EXPRESSION The EXPRESSION is false.
-n STRING The length of STRING is greater than zero.
-z STRING The lengh of STRING is zero (ie it is empty).
STRING1 = STRING2 STRING1 is equal to STRING2
STRING1 != STRING2 STRING1 is not equal to STRING2
INTEGER1 -eq INTEGER2 INTEGER1 is numerically equal to INTEGER2
INTEGER1 -gt INTEGER2 INTEGER1 is numerically greater than INTEGER2
INTEGER1 -lt INTEGER2 INTEGER1 is numerically less than INTEGER2
-d FILE FILE exists and is a directory.
-e FILE FILE exists.
-r FILE FILE exists and the read permission is granted.
-s FILE FILE exists and it’s size is greater than zero (ie. it is not empty).
-w FILE FILE exists and the write permission is granted.
-x FILE FILE exists and the execute permission is granted.

 

Functions

function <name> or <name>() {  <commands>  } Create a function called name. Must appear in the script before any calls to the function. Arguments are passed as to the script $1, $2…
return <value> Exit the function with a return status of value.
local <name>=<value>  Create a local variable within a function.
command <command> Run the command with that name as opposed to the function with the same name.

print_something () {
echo Hello $1
return 5
}
print_something Mars
print_something Jupiter
echo The previous function has a return value of $?

Hello Mars
Hello Jupiter
The previous function has a return value of 5

tput


#!/bin/bash
# Print message in center of terminal
cols=$( tput cols )
rows=$( tput lines )
message=$@
input_length=${#message}
half_input_length=$(( $input_length / 2 ))
middle_row=$(( $rows / 2 ))
middle_col=$(( ($cols / 2) - $half_input_length ))
tput clear
tput cup $middle_row $middle_col
tput bold
echo $@
tput sgr0
tput cup $( tput lines ) 0

tput cols will tell us how many columns the terminal has.
tput lines will tell us how many lines (or rows) the terminal has.
Take all the command line arguments and assign them to a single variable message.
Find out how many characters are in the string message. We had to assign all the input values to the variable message first as ${#@} would tell us how many command line arguments there were instead of the number of characters combined.
We need to know what 1/2 the length of the string message is in order to center it.
Calculate where to place the message for it to be centered.
tput clear will clear the terminal.
tput cup will place the cursor at the given row and column.
tput bold will make everything printed to the screen bold.
Now we have everything set up let’s print our message.
tput sgr0 will turn bold off (and any other changes we may have made).
tput cup $( tput lines ) 0Place the prompt at the bottom of the screen.

Bash Tutorial
Advanced Bash Scripting

Check Ubuntu Hardware

Read More

List summary of hardware:
lshw -short
List summary of PCI devices:
lspci -v

H/W path Device Class Description
===========================================================
system PowerEdge R420 (SKU=NotProvided;ModelName=PowerEdge R420)
/0 bus 0K29HN
/0/0 memory 64KiB BIOS
/0/400 processor Intel(R) Xeon(R) CPU E5-2403 v2 @ 1.80GHz
/0/400/700 memory 128KiB L1 cache
/0/400/701 memory 1MiB L2 cache
/0/400/702 memory 10MiB L3 cache
/0/401 processor Intel(R) Xeon(R) CPU E5-2403 v2 @ 1.80GHz
/0/401/703 memory 128KiB L1 cache
/0/401/704 memory 1MiB L2 cache
/0/401/705 memory 10MiB L3 cache
/0/1000 memory 16GiB System Memory
/0/1000/0 memory 4GiB DIMM DDR3 Synchronous 1600 MHz (0,6 ns)
/0/1000/1 memory 4GiB DIMM DDR3 Synchronous 1600 MHz (0,6 ns)
/0/1000/2 memory DIMM DDR3 Synchronous [empty] /0/1000/3 memory DIMM DDR3 Synchronous [empty] /0/1000/4 memory DIMM DDR3 Synchronous [empty] /0/1000/5 memory DIMM DDR3 Synchronous [empty] /0/1000/6 memory 4GiB DIMM DDR3 Synchronous 1600 MHz (0,6 ns)
/0/1000/7 memory 4GiB DIMM DDR3 Synchronous 1600 MHz (0,6 ns)
/0/1000/8 memory DIMM DDR3 Synchronous [empty] /0/1000/9 memory DIMM DDR3 Synchronous [empty] /0/1000/a memory DIMM DDR3 Synchronous [empty] /0/1000/b memory DIMM DDR3 Synchronous [empty] /0/100 bridge Xeon E7 v2/Xeon E5 v2/Core i7 DMI2
/0/100/1 bridge Xeon E7 v2/Xeon E5 v2/Core i7 PCI Express Root Port 1a
/0/100/1/0 scsi0 storage MegaRAID SAS 2008 [Falcon] /0/100/1/0/0.20.0 generic BP12G+
/0/100/1/0/2.0.0 /dev/sda disk 999GB PERC H310
/0/100/1/0/2.0.0/1 /dev/sda1 volume 243MiB Linux filesystem partition
/0/100/1/0/2.0.0/2 /dev/sda2 volume 930GiB Extended partition
/0/100/1/0/2.0.0/2/5 /dev/sda5 volume 930GiB Linux LVM Physical Volume partition
/0/100/3 bridge Xeon E7 v2/Xeon E5 v2/Core i7 PCI Express Root Port 3a
/0/100/5 generic Xeon E7 v2/Xeon E5 v2/Core i7 VTd/Memory Map/Misc
/0/100/5.2 generic Xeon E7 v2/Xeon E5 v2/Core i7 IIO RAS
/0/100/11 bridge C600/X79 series chipset PCI Express Virtual Root Port
/0/100/16 communication C600/X79 series chipset MEI Controller #1
/0/100/16.1 communication C600/X79 series chipset MEI Controller #2
/0/100/1a bus C600/X79 series chipset USB2 Enhanced Host Controller #2
/0/100/1c bridge C600/X79 series chipset PCI Express Root Port 1
/0/100/1c.4 bridge C600/X79 series chipset PCI Express Root Port 5
/0/100/1c.4/0 em1 network NetXtreme BCM5720 Gigabit Ethernet PCIe
/0/100/1c.4/0.1 em2 network NetXtreme BCM5720 Gigabit Ethernet PCIe
/0/100/1c.7 bridge C600/X79 series chipset PCI Express Root Port 8
/0/100/1c.7/0 bridge SH7757 PCIe Switch [PS] /0/100/1c.7/0/0 bridge SH7757 PCIe Switch [PS] /0/100/1c.7/0/0/0 bridge SH7757 PCIe-PCI Bridge [PPB] /0/100/1c.7/0/0/0/0 display G200eR2
/0/100/1c.7/0/1 bridge SH7757 PCIe Switch [PS] /0/100/1d bus C600/X79 series chipset USB2 Enhanced Host Controller #1
/0/100/1e bridge 82801 PCI Bridge
/0/100/1f bridge C600/X79 series chipset LPC Controller
/0/100/1f.2 storage C600/X79 series chipset 6-Port SATA AHCI Controller
/0/1 generic Xeon E7 v2/Xeon E5 v2/Core i7 QPI Link 0
/0/2 generic Xeon E7 v2/Xeon E5 v2/Core i7 QPI Link 1
/0/4 generic Xeon E7 v2/Xeon E5 v2/Core i7 Power Control Unit 0
/0/6 generic Xeon E7 v2/Xeon E5 v2/Core i7 Power Control Unit 1
/0/7 generic Xeon E7 v2/Xeon E5 v2/Core i7 Power Control Unit 2
/0/8 generic Xeon E7 v2/Xeon E5 v2/Core i7 Power Control Unit 3
/0/9 generic Xeon E7 v2/Xeon E5 v2/Core i7 UBOX Registers
/0/a generic Xeon E7 v2/Xeon E5 v2/Core i7 UBOX Registers
/0/b generic Xeon E7 v2/Xeon E5 v2/Core i7 Unicast Registers
/0/c generic Xeon E7 v2/Xeon E5 v2/Core i7 Unicast Registers
/0/d generic Xeon E7 v2/Xeon E5 v2/Core i7 Unicast Registers
/0/e generic Xeon E7 v2/Xeon E5 v2/Core i7 Unicast Registers
/0/f generic Xeon E7 v2/Xeon E5 v2/Core i7 Home Agent 0
/0/10 generic Xeon E7 v2/Xeon E5 v2/Core i7 Home Agent 0
/0/11 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 0 Target Address/Thermal Registers
/0/12 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 0 RAS Registers
/0/13 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 0 Channel Target Address Decoder Registers
/0/14 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 0 Channel Target Address Decoder Registers
/0/15 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 0 Channel Target Address Decoder Registers
/0/16 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 0 Channel Target Address Decoder Registers
/0/17 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 Thermal Control 0
/0/18 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 Thermal Control 1
/0/19 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 ERROR Registers 0
/0/1a generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 ERROR Registers 1
/0/1b generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 Thermal Control 2
/0/1c generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 Thermal Control 3
/0/1d generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 ERROR Registers 3
/0/1e generic Xeon E7 v2/Xeon E5 v2/Core i7 R2PCIe
/0/1f generic Xeon E7 v2/Xeon E5 v2/Core i7 R2PCIe
/0/20 generic Xeon E7 v2/Xeon E5 v2/Core i7 QPI Ring Registers
/0/21 generic Xeon E7 v2/Xeon E5 v2/Core i7 QPI Ring Performance Ring Monitoring
/0/22 generic Xeon E7 v2/Xeon E5 v2/Core i7 System Address Decoder
/0/23 generic Xeon E7 v2/Xeon E5 v2/Core i7 Broadcast Registers
/0/24 generic Xeon E7 v2/Xeon E5 v2/Core i7 Broadcast Registers
/0/3 bridge Xeon E7 v2/Xeon E5 v2/Core i7 PCI Express Root Port 3a
/0/5 generic Xeon E7 v2/Xeon E5 v2/Core i7 VTd/Memory Map/Misc
/0/5.2 generic Xeon E7 v2/Xeon E5 v2/Core i7 IIO RAS
/0/25 generic Xeon E7 v2/Xeon E5 v2/Core i7 QPI Link 0
/0/26 generic Xeon E7 v2/Xeon E5 v2/Core i7 QPI Link 1
/0/27 generic Xeon E7 v2/Xeon E5 v2/Core i7 Power Control Unit 0
/0/28 generic Xeon E7 v2/Xeon E5 v2/Core i7 Power Control Unit 1
/0/29 generic Xeon E7 v2/Xeon E5 v2/Core i7 Power Control Unit 2
/0/2a generic Xeon E7 v2/Xeon E5 v2/Core i7 Power Control Unit 3
/0/2b generic Xeon E7 v2/Xeon E5 v2/Core i7 UBOX Registers
/0/2c generic Xeon E7 v2/Xeon E5 v2/Core i7 UBOX Registers
/0/2d generic Xeon E7 v2/Xeon E5 v2/Core i7 Unicast Registers
/0/2e generic Xeon E7 v2/Xeon E5 v2/Core i7 Unicast Registers
/0/2f generic Xeon E7 v2/Xeon E5 v2/Core i7 Unicast Registers
/0/30 generic Xeon E7 v2/Xeon E5 v2/Core i7 Unicast Registers
/0/31 generic Xeon E7 v2/Xeon E5 v2/Core i7 Home Agent 0
/0/32 generic Xeon E7 v2/Xeon E5 v2/Core i7 Home Agent 0
/0/33 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 0 Target Address/Thermal Registers
/0/34 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 0 RAS Registers
/0/35 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 0 Channel Target Address Decoder Registers
/0/36 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 0 Channel Target Address Decoder Registers
/0/37 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 0 Channel Target Address Decoder Registers
/0/38 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 0 Channel Target Address Decoder Registers
/0/39 generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 Thermal Control 0
/0/3a generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 Thermal Control 1
/0/3b generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 ERROR Registers 0
/0/3c generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 ERROR Registers 1
/0/3d generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 Thermal Control 2
/0/3e generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 Thermal Control 3
/0/3f generic Xeon E7 v2/Xeon E5 v2/Core i7 Integrated Memory Controller 1 Channel 0-3 ERROR Registers 3
/0/40 generic Xeon E7 v2/Xeon E5 v2/Core i7 R2PCIe
/0/41 generic Xeon E7 v2/Xeon E5 v2/Core i7 R2PCIe
/0/42 generic Xeon E7 v2/Xeon E5 v2/Core i7 QPI Ring Registers
/0/43 generic Xeon E7 v2/Xeon E5 v2/Core i7 QPI Ring Performance Ring Monitoring
/0/44 generic Xeon E7 v2/Xeon E5 v2/Core i7 System Address Decoder
/0/45 generic Xeon E7 v2/Xeon E5 v2/Core i7 Broadcast Registers
/0/46 generic Xeon E7 v2/Xeon E5 v2/Core i7 Broadcast Registers

Commands to check spam in Ubuntu with Postfix

Read More

mailq   Watch the mail queue
postfix -f  Flush the mail queue
postsuper -d ALL To remove all mails from the queue
postsuper -d deferred deferred To remove all mails in the deferred queue
find /var/spool/postfix/deferred -type f | wc -l    To know the number of messages sitting in the deferred queue
postcat -vq ID To view message content in queue with ID
qshape active Display number of emails being sent to each domain and how long they have been in the active queue
qshape deferred Display differed queue
tail -f /var/log/mail.log View the log in realtime
To check mail log for sent messages
cat /var/log/mail.log |grep -v "relay=local" |grep "relay=" |grep "status=sent"

To get statistics, install a script:

wget http://jimsun.linxnet.com/downloads/pflogsumm-1.1.1.tar.gz
tar -zxf pflogsumm-1.1.1.tar.gz
chown root:root pflogsumm-1.1.1
cd pflogsumm-1.1.1
cat /var/log/mail.log | ./pflogsumm.pl

You can move pflogsumm.pl to /usr/local/bin

To send a weekly report

Create /etc/cron.weekly/mailreport
#!/bin/sh
#
# mailreport cron weekly
MailSubject="Email report $(date +%d-%m-%Y)"
cat /var/log/mail.log | /usr/local/bin/pflogsumm.pl | /usr/bin/mailx -s "$MailSubject" your.mail@domain.com
exit 0

Change file permissions to read, execute
chown root:root /etc/cron.weekly/mailreport
chmod 755 /etc/cron.weekly/mailreport

Report today problems

pflogsumm -d today /var/log/mail.log --problems_first

Get permanent errors hard bounces
grep " dsn=5." /var/log/mail.log | grep -o -P " to=<(.+?)>" | sort | uniq -c
Get soft bounces
They start with 4…
grep " dsn=4." /var/log/mail.log | grep -o -P " to=<(.+?)>" | sort | uniq -c

To check user logins

grep "sasl_method=LOGIN" /var/log/mail.log

PDFtk server

Read More

 

Build PDFtk Server

You can compile PDFtk Server from its source code. PDFtk Server is known to compile and run on Debian, Ubuntu Linux, FreeBSD, Slackware Linux, SuSE, Solaris and HP-UX.

  • Download and unpack: pdftk-2.02-src.zip (~2MB)
  • Review the pdftk license information in: license_gpl_pdftk/readme.txt.
  • Review the Makefile provided for your platform and confim that TOOLPATH and VERSUFF suit your installation of gcc/gcj/libgcj. If you run apropos gcc and it returns something like gcc-4.5, then set VERSUFF to -4.5. The TOOLPATH probably doesn’t need set.
  • Change into the pdftk sub-directory,
  • run make -f Makefile.Debian (substitute your platform’s Makefile filename)

We have built pdftk using gcc/gcj/libgcj versions 3.4.5, 4.4.1, 4.5.0 and 4.6.3. Pdftk 1.4x fails to build on gcc 3.3.5 due to missing libgcj features. If you are using gcc 3.3 or older, try building pdftk 1.12 instead.

https://www.pdflabs.com/
Local download: pdftk-2.02-src.zip

Useful terminal commands in Ubuntu

Read More
INSTALL COMMAND-LINE INTERFACE (CLI) SOFTWARESome of the commands listed below are not available in Ubuntu or Debian by default.

To install the remaining CLI software, download the installation script install-additional-cli-software.sh, open your terminal, and execute it: bash install-cli-software.sh.

1. ESSENTIAL COMMANDS

  • Navigation: pwd, ls, cd folder (folders are case sensitive!), cd ...
  • File manipulation: cat, cp, ln, mkdir, mv, rm, rmdir, touch.
  • Help: man terminal_command .
  • Permissions: chgrp, chmod, chown, su, sudo.
  • Search: find.
  • Text editors: ed, nano, vi, vim.
  • Text file visualization: head, less, more, tail.
  • Install a package: sudo apt-get install package.
  • Uninstall a package: sudo apt-get purge package.
  • Remove packages that are no longer needed: sudo apt-get autoremove.

2. BASH SHORTCUTS

  • Autocomplete files, folders, commands, packages, etc.: Tab.
  • List all available files, folders, commands, packages, etc.: Tab + Tab.
  • Go to previous command: , or Ctrl + P.
  • Go to next command: , or Ctrl + N.
  • Search through previously used commands: Ctrl + R.
  • Interrupt whatever you are running: Ctrl + C.

2. BASIC COMMANDS

  • Compare files line by line: colordiff, diff, vimdiff, wdiff.
  • List files in databases that match a pattern: locate, sudo updatedb.
  • Network interface: ifconfig.
  • Report disk space usage: df -H, du -hs folder.
  • OpenSSH SSH client with X11 forwarding: ssh user@server -X.
  • Print lines matching a pattern from a text file: grep.
  • Print newline, word, and byte counts for each file: wc.
  • Secure copy (remote file copy program): scp.
  • Show current processes: htop, ps, top.

3. SCREEN COMMANDS

  • Create a screen session: screen.
  • Detach from the current screen session: Ctrl + A then D.
  • List the screen session identification strings: screen -ls.
  • Reattach to a screen session: screen -r session_id_string.
  • Terminate the current screen session: exit, or Ctrl + A then :quit.
  • Scroll up/down during session: Ctrl + A then Esc then //PgUp/PgDn.

4. OTHER COMMANDS

  • Extract an ISO file: 7z x filename.iso.
  • Report faked system time to programs: faketime.
  • Retrieves files from the web: wget.
  • Print shared library dependencies: ldd executable_filename.
  • Make symbolic links: ln -s input_filename output_link_name.
  • List block devices: lsblk.
  • Format USB stick as VFAT: sudo mkfs.vfat -I /dev/sdx -n NAME && sync.
  • Restore disk from image: sudo dd bs=1M if=im.iso of=/dev/sdx && sync.

5. FFMPEG COMMANDS

  • Convert image to 5 sec. video: ffmpeg -loop 1 -i 01.png -t 5 out.mp4.
  • 15 images to 30 Hz 5 sec. video: ffmpeg -r 3 -i %03d.png -r 30 out.mp4.
  • Resize video to 720p: ffmpeg -i input.webm -s 1280x720 output.webm.
  • Fade in the first 25 frames and fade out the last 25 frames of a 1000-frame video: ffmpeg -i in.mp4 -vf "fade=in:0:25, fade=out:975:25" out.mp4.
  • Concatenate videos: ffmpeg -f concat -i mylist.txt -c copy out.mp4.

6. SVN COMMANDS

  • Create new repository: svnadmin create repository_name.
  • Checkout: svn co svn+ssh://user@server/path/to/repository.
  • Update working copy: svn update.
  • Get status of current copy: svn status.
  • Add all items recursively: svn add *.
  • Add an item (if folder, adds recursively): svn add item_name.
  • Delete an item (if folder, deletes recursively): svn delete item_name.
  • Commit with log message: svn commit -m 'message'.

7. FIND EXAMPLES

  • Run files recursively in current dir.: find . -type f -exec file '{}' \;.
  • Delete all .svn folders: find . -iname .svn -prune -exec rm -r '{}' \;.
  • Copy all png files to png: find ./ -name *.png -exec cp '{}' ./png \;.

8. PDFTK EXAMPLES

  • Join all PDF files into a new PDF file: pdftk *.pdf cat output out.pdf.
  • Join 3 PDF files: pdftk in1.pdf in2.pdf in3.pdf cat output out.pdf.
  • Extract pages from a PDF: pdftk in.pdf cat 1 25-35 end output out.pdf.

http://milq.github.io/useful-terminal-commands-ubuntu-debian

Manuel Ignacio López Quintero

Byobu

Read More

It allows for the execution of multiple shells in one terminal. Byobu now includes an enhanced profiles, convenient keybindings, configuration utilities, and toggle-able system status notifications.

Invoke it simply with:
byobu

Now bring up the configuration menu. By default this is done by pressing the F9 key. This will allow you to:

  • View the Help menu

  • Change Byobu’s background color

  • Change Byobu’s foreground color

  • Toggle status notifications

  • Change the key binding set

  • Change the escape sequence

  • Create new windows

  • Manage the default windows

  • Byobu currently does not launch at login (toggle on)

The key bindings determine such things as the escape sequence, new window, change window, etc. There are two key binding sets to choose from f-keys and screen-escape-keys. If you wish to use the original key bindings choose the none set.

byobu provides a menu which displays the Ubuntu release, processor information, memory information, and the time and date. The effect is similar to a desktop menu.

Using the “Byobu currently does not launch at login (toggle on)” option will cause byobu to be executed any time a terminal is opened. Changes made to byobu are on a per user basis, and will not affect other users on the system.

One difference when using byobu is the scrollback mode. Press the F7 key to enter scrollback mode. Scrollback mode allows you to navigate past output using vi like commands. Here is a quick list of movement commands:

  • h – Move the cursor left by one character

  • j – Move the cursor down by one line

  • k – Move the cursor up by one line

  • l – Move the cursor right by one character

  • 0 – Move to the beginning of the current line

  • $ – Move to the end of the current line

  • G – Moves to the specified line (defaults to the end of the buffer)

  • / – Search forward

  • ? – Search backward

  • n – Moves to the next match, either forward or backward

    https://help.ubuntu.com/lts/serverguide/byobu.html

    http://byobu.co/

Scripts in /etc/cron.daily (or the other Cron directories)

Read More

Remember that you can not place scripts with a “.” in the name. The name must consist of all upper,lower,numbers,hyphens, or underscores. The reason is run-parts will not pickup the files that do not follow this rule.
To check the scripts running on this directory:
run-parts --test /etc/cron.daily

The user crontabs, as given by crontab -e or crontab -l, are NOT system crontabs.