arttuladhar
5/13/2017 - 12:44 AM

Handy Linux command line tricks

Handy Linux Commands

Some handy Linux command line tricks

Delete All JSON files in a directory

for files in *.json; do rm "$files"; done

Scp Multiple Files

for files in *.json; do scp "$files" art@art-server:/apps/art/data/app/json/.; done

Create Split Zip Archive

zip -r -s 100m ArchiveName.zip FolderName

Join Split

zip -s0 ArchiveName.zip --out new.zip

Set TimeZone

timedatectl set-timezone America/Chicago

Zip/Tar Each File Individually

find . -name '*.csv' -exec zip '{}.zip' '{}' \;
find . -name '*.csv' -exec tar -zcvf '{}.tgz' '{}' \;

Add Line to Top of File

{ echo -e 'Line 0'; cat file; } > file1

Find Largest File Under Directory

du -a * | sort -r -n | head -10

Cut CSV Fields to Different File

cut -f 1,3domains-group -d , 000000_0 > update_000000_0

Compress Director

tar -zcvf compressFileName.tar.gz folderToCompress

Issuing Remote Commands over SSH

user=art
ip=192.168.1.1
command="cat"

ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no $user@$ip $command

Using Sequence

for i in `seq -w 0 10`; do echo "Hello $i"; done;