The at command can be used to schedule jobs to be run at certain times. I have a hard time getting up in the morning. Here, we’re going to echo a command that we want to be run at a certain time. In this case, we’re going to open a song to make into our alarm clock: echo 'open ~/Desktop/bangbang.m4v 2>/dev/null' | at 07:00 tomorrow The job will then output. You can see jobs waiting to be run, along with when they’ll be run using the at command with the -l option: at -l In this case, the job is 2. You can then remove a job using the atrm command: atrm job…
-
-
Get Line Numbers With The Less Command
One of the great things about cat is that you can view the contents of a file with line numbers. You do so using the -n option, as follows: cat -n ~/Desktop/myFile Sometimes a file is too big to view though, so you can pipe the output to less, to combine some of the best features of each: cat -n ~/Desktop/myFile | less Obviously, the same thing would work with more: cat -n ~/Desktop/myFile | less You can also do something similar with the grep command and the -n option: grep -n ^ ~/Desktop/myFile | less Enjoy.
-
cd To The Previous Directory
The cd command has lots of fun little shortcuts. One I use frequently is the -. The ~ always takes you to your home directory, but using cd – will take you to the last directory you were in. For example, if you do the following on a Mac: cd ~ Then you do .. (which is a shortcut for the directory above the one you’re in): cd .. Then pwd will show that you’re in /Users. But, if you cd to – again: cd - Now you’re back in your home folder. The – expands to OLDPWD. Quick tip. Nothing more to see here.
-
What I Think Of When I Open My SDK
-
Create 10,000 Empty Directories for Testing
The mkdir command is used to create directories. Sometimes, in testing, you need to have a lot of directories. So, you can use the following command to create 10,000 5 digit directories, named 00001 to 10000: mkdir $(printf '%05d\n' {1..10000})
-
Count Log Entries for a Pattern
You see a lot of entries for various things in log files. Here, we’re going to print out the number of entries with backupd in them: awk '/backupd/{print NR}' /var/log/system.log
-
Bash: A Silly wc Example
The wc command is used to count words, characters and lines. Here, we’ll run it a few different ways. -l shows the number of lines in a file. For example, in my home directory, I can use it to see how many lines are in my .gitconfig file: wc -l .gitconfig This would output something like the following: 11 .gitconfig Or count the number of characters with -c: wc -c .gitconfig Or check the number of words: wc -w .gitconfig You can also run it against multiple files. For example, here I’ll check the number of lines in both my .gitconfig file and my .gitignore_global files: wc -l .gitconfig .gitignore_global…
-
Remove All Files Except jamf.log From A Directory
You can redirect a log file into a given directory. That directory, if it has other stuff in it, can get out of control. So, here, we’re going to remove all files except that file using the find command: find * ! -name jamf.log -type f -delete Once run, the jamf.log is the last file left in the directory.
-
Kill Processes With Open Handles on PIDs
You can kill a process using the kill command. You can use lsof with -n to see the processes that have connections to a file. So, here, you can see lsof showing all files with an open connection: lsof -n You can also use the-c option to constrain output to a specific string. The kill command can then use the lsof command to kill all those processes, as follows: kill -HUP $(lsof -n -c /tty/i -t) Free your files…
-
Basic bash Looping
In bash, there area number of ways you can write loops. Here, we’ll look at putting a single line with a loop in it. This will be done using the for command. For requires a do and a done. The do is what we’ll do for each iteration. Here, we’ll just run a loop from 1 to 10 and then we’ll do an echo on that variable so it displays on the screen as well loop: for i in {1..10} ; do echo $i; done The output would then be as follows: 1 2 3 4 5 6 7 8 9 10