Posts

List of PIDs only

I wanted a list of pids only so I could run them through a while loop for processing. To get just a list of pids on Linux I used: ps --no-headers -o pid -C processname

Get filename without path, filename without extension, extension of filename in Bash

SOURCE Get filename without path basefilename=$(basename /full/path/to/file.txt) Get filename without extension filewoext="${basefilename%.*}" Get extension of file fileext="${basefilename##*.}"

Arrays in Bash

#!/usr/bin/env bash # Create the array myarray = () # Add items to the array # Add a sequence of numbers from 1 to 16 #for item in {0..16} cd ~/Documents/ # Add a list of files to the array # List all *.txt files in the ~/Documents directory and grab the three oldest # To grab the 3 most recent files use ls -rt. Order by time in reverse with most recent listed last for item in $( ls -t *.txt  | tail -3 ) do   myarray+ = (" ${item} ") done # Iterate over the array and print out items for item in ${myarray[ @ ]} do   printf " Item: ${item}\n " done # Print out the number of elements in the array printf " ${#myarray[ @ ]}\n "

Fedora 23 netinstall URL

Not sure why I found this so challenging, maybe because I haven't done a netinstall in ages. Anyway, finally figured out how to setup the Installation Source your selected mirror/path/to/installation/end with os/ So for me it was: http://fedora.mirrors.tds.net/fedora/releases/23/Server/x86_64/os/ Key was to end it with os/.

Move directory in one git repository to another repository

I've been looking for a way to move a directory in a git repository to a new repository and preserve the history. We are reorganizing some code at work so that's what prompted me to start looking. The scenario is I have a repository and structure that looks like the following: repoA/  file1  file2  file3  directory1/   file1a   file1b   file1c  directory2/   file2a   file2b I want to move directory1 and all of the files in that directory(file1a, file1b, file1c) to a new git repository and preserve the change history. I want to end up with the following: repoB/  directory1/   file1a   file1b   file1c The  solution is here . I started with  this solution  but with the second solution I ended up with the files from my directory1 in the root of the repo. By the time I moved the files into a new directory1 the change history was stored in the root directory of the new repo so if I was i...

Get PID from running process

pgrep -f processname(i.e. vim, emacs, postgres, etc.)

Too many files for ls

Using ls you receive the error that there are too many arguments: Example: find /path/to/files/ -name "*.ZIP" -exec basename {} \;