Get a filename only list of files in a folder

To get a list of all files in a folder without path, you can use the following snippet:

Example result:

Prefix files: If you want to prefix files, you can use the same command too:

Example result:

 

Remove all files and folders including hidden files on bash

To remove all files and folders including hidden files such .gitignore, .htaccess, .git etc. on bash you can use the following command:

Is the same as:

But ever shorter. ūüėČ

Delete x files from folder in a for i loop

Recently I tried to remove a big bunch of files from one of my raspberry pies where ffmpeg had swamped my SD-card with too many capture images. So I had to delete x files from folder. I just tried:

But that gave me an “unable to execute /bin/rm: Argument list too long” error message. […]

Lock shellscript process under Unix based systems

Today I ran again into a common problem when dealing with cron based scipts that run concurrently. That’s why I had to lock shellscript process until it is finished before starting the next executing round. On Unix based systems like Linux you can achieve that with flock. flock binds¬†a file descriptor to a certain lock […]

Find and replace malware code blocks in php files via shell

Today I was attacked by an unknown bot or something like that. It placed the following code in many hundred index.php files on one of my servers, because the FTP-Password was cracked.

The solution was the following little Python script that walks through¬†the filesystem tree and searches for index.php’s. In every matched file it […]

Associative arrays (hash, dictionary) on bash

This is how to create associative arrays (hash, dictionary) on bash:

This script was made to¬†purge the varnish on one of my clusters. But the important stuff is the declaration of the associative array with¬† DOMAINS['LIVE']="www.ask-sheldon.com";¬†and how to access the values of the array (with¬† REQUEST_DOMAIN=${DOMAINS["$1"]};). “$1” is the array key to select the value. By the […]

Compress and extract files

With tar On Unix based plattforms you can use the tar command for file compression and also for later uncompression. Compression

With -h as the first parameter the real files instead symbolic links are compressed. So you can tar symbolic link targets. To exclude files or folder, you can define¬†–exclude=’fileOFolderPath’ directly after the tar command. […]