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
-
Separate commands on one line in Bash
In bash, you can run multiple commands in a single line of a script. You do so by separating them with a semi-colon (;). The great thing about this is that if you end up using a variable, you can pass it on to subsequent commands. Here, we’re going to string three commands together and then echo the output: a=1;b=2;c=$a+$b;echo $c because we told c to be $a + $b, the $a expands to 1 and the $b expands to 2, we throw them together and then echo out the contents of c$ which appears as follows: 1+2 Now, we could have this thing do math as well, by wrapping…
-
Resolve InnoDB Errors In MySQL
Database won’t start? InnoDB errors are a pain. Where was krypted for a month? Did everything finally get to me and I gave up blogging? No, the site ended up having some problems with corruption in some rows of the InnoDB tables. But, I was able to get the site back up by putting the database into recovery mode. How did I do this? It’s pretty straight forward. Open my.cnf and paste these lines in there: innodb_force_recovery=3 innodb_purge_threads=0 Once the corruption is resolved, bring up empty databases and import your mysqldump into the new databases and link your site back up. But, the InnoDB force recovery puts the database into…
-
See Version Information In Linux
There are a number of ways to see information about what version of Linux that you’re running on different cat /etc/lsb-release Which returns the distribution information, parsed as follows: DISTRIB_ID=Ubuntu DISTRIB_RELEASE=12.04.5 DISTRIB_CODENAME=precise DISTRIB_DESCRIPTION="Ubuntu Precise Pangolin (LTS)" LSB_release can also be run as a command, as follows: lsb_release -a Which returns the following: No LSB modules are available. Distributor ID: Ubuntu Description: Ubuntu Precise Pangolin (LTS) Release: 12.04.5 Codename: precise lab_release can be used as a command as well: cat /etc/issue.net Which returns: Ubuntu Precise Pangolin (development branch) In Debian, you can simply look at the version file: cat /etc/debian_version Which returns the following: wheezy/sid Or Red Hat Enterprise can also…
-
Install Pow for Rails Testing On OS X
Pow is a Rack server for OS X. It’s quick and easy to use and lets you skip that whole update an Apache file, then edit /etc/hosts, ethane move a file, then run an app type of process. To get started with Pow, curl it down and pipe it to a shell, then provide the password when prompted to do so: odr:~ charlesedge$ curl get.pow.cx | sh % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 9039 100 9039 0 0 10995 0 --:--:-- --:--:-- --:--:-- 10996 *** Installing Pow 0.5.0... *** Installing local configuration files... /Users/charlesedge/Library/LaunchAgents/cx.pow.powd.plist *** Installing system…
-
Linux Bash Commands
Popped in a list of Linux bash commands here: https://krypted.com//commands/linux-bash-commands/
-
Linux and Free Memory Space
The free command in Linux is used to show memory utilization. When run without any options, you can see the used and available space of swap and physical memory. By default, the option is displayed in kilobytes but when run with a -b option it is shown in bytes or -m will show in megabytes or -g in gigabytes or -t in terabytes. So to see the free space in bytes run the following: free -b The -o option shows the output adjusted for the buffer. The -t option also adds a total column as well as a line for total that shows swap and physical, combined. The -s will update…