Each program has a set of file descriptors. It’s like an open stream from / to file. On start program has 3 descriptors: standard input (stdin), standard output (stdout) and standard error (stderr). They has numbers: from 0 to 2. Standard input is used for reading input data from the user (from the terminal). StandardContinue Reading
Tag: Bash
How to get top 10 largest files
As we already saw, we can easily get to 10 largest directories (see “How to get top 10 largest directories in the current directory“). But there we used du utility – it shows directory size (or “estimate file space usage”). What utility shows file size? Oh… It’s just the ls! Looks easy? But we needContinue Reading
Three useful keys of tail util
tail – output the last part of files. Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each with a header giving the file name. With no FILE, or when FILE is -, read standard input. Tail’s keys Show last ‘num’ lines in file: tail -n {{num}}Continue Reading
How to get top 10 largest directories in the current directory
Sometimes it’s not obvious, which directory is too big. To find the biggest directories in you computer, you may use graphic user interface and some of supported file managers. But what will you do when you don’t have a GUI? And it’s not mythical situation. On the desktop you almost always know the biggest directoryContinue Reading
Useful keyboard shortcuts in Bash for beginners
Hotkeys in Bash helps you use Bash more efficiency. Most of them have slower analogs. But some of them help you easier do common things. Ctrl + a – Return to the start of the command you’re typing Ctrl + e – Go to the end of the command you’re typing Ctrl + u – Cut everything beforeContinue Reading
Bash history util for beginners
history is a program for tracking terminal input. Many programs read input from the user a line at a time. The GNU History library is able to keep track of those lines. It associates arbitrary data with each line, and utilize information from previous lines in composing new ones. Tips and examples Display the commandsContinue Reading
How to fix the last command in Bash
Sometimes we all makes mistakes. And it’s good if this is just typo in command name and we don’t erase important data. So, if it was just a typo Bash gives to us easy way to fix it! Takes the last command, replaces string1 with string2 and executes it. ^string1^string2 For example: $ ehco fooContinue Reading
Useful shortcuts for Beginners in Bash – BANG!
Bash is not the only programming language. The most important it’s a shell. When you run a terminal, you get a bourne-again Shell. And it has special shortcuts and predefined special variables. For example, $? contains the last exit code, $PS1 is a template of Bash prompt. But now we’ll talk about “bang” shortcuts. Examples:Continue Reading
How to count words with grep
Grep command in Unix/Linux is the short form of ‘global search for the regular expression’. The grep command is a filter that is used to search for lines matching a specified pattern and print the matching lines to standard output. Piping to wc util is slow: ~ $ time grep and tmp/a/longfile.txt | wc -l2811real 0m0.097s userContinue Reading
Less utility for beginners
less is a terminal pager program for Linux, MacOS (Unixes) and even Windows. It’s used to viewing (but not changing) the contents of a text file one screen at a time. You can try in you terminal: less /etc/passwd – if you use Unix-like system. Note: press q to quit. Most Linux users know about navigationContinue Reading