Some very useful Linux bash functions.

Show a preview of a directory as you cd into it. c() { cd "$@" ls_truncate=20 files=$(ls -F -C –color=always) files_num=$(echo "$files" | wc -l) echo "$files" | head -n $ls_truncate [ $(echo "$files" | wc -l) -gt "$ls_truncate" ] && echo "(Ommited $((files_num-$ls_truncate)) files/directories)" }c() { cd "$@" ls_truncate=20 files=$(ls -F -C –color=always) files_num=$(echo … Read more

More awesome shell tricks for the Linux command line. This is using the bash shell.

This is another way to see where you are in the directory stack. homer@deep-thought ~/Documents/basenew $ echo $DIRSTACK ~/Documents/basenewhomer@deep-thought ~/Documents/basenew $ echo $DIRSTACK ~/Documents/basenew Here is another way to show the $PWD value one directory down from where you are now. homer@deep-thought ~/Documents/basenew $ echo $OLDPWD /home/homer/Documentshomer@deep-thought ~/Documents/basenew $ echo $OLDPWD /home/homer/Documents This example shows … Read more

Running a command within another program. How to do this with C.

This code snippet will run the date command. The execl() function is very useful for executing a command within your C program.You replace the NULL identifiers with any extra arguments to pass to the program. I prefer this over the system() function. #include <unistd.h>   int main(void) {   execl("/bin/date", "%c", NULL, NULL, NULL); return … Read more