Pages

Thursday, April 21, 2016

Linux Command One Liners - Exercise


  • To empty a file or truncate a file to 0 size
  • To replace content of a file
  • To append content to a file as a new line
  • To append content to a file without new line (by continuing last line )
  • To append content to a file 
  • To read first line of a file and store it in a variable 
  • To read a file line by line and store it in a variable
  • To read random line from a file and store it in a variable
  • To read only 3 columns/fields form a file into variables
  • To find number of lines, words, characters in a file and store it in a variable
  • To find value in 2nd and 5th column of a one line variable and store it in a variable
  • To find size of file and store it in a variable
  • To make a copy of file
  • To move or rename a file
  • To generate Small letter a to z (with spaces between characters)
  • To generate Capital letter A to Z (with spaces between characters)
  • To generate Small letter a to z (without spaces between characters)
  • To generate Capital letter A to Z (without spaces between characters)
  • To generate all letters in a column output and store it in a variable
  • To generate numbers from 1 to 100 (with spaces between numbers)
  • To generate numbers from 1 to 100 (in column format)
  • To generate numbers 0 to 9 with a leading zero as pad
  • To generate n number of words 
  • To generate alphanumeric strings
  • To generate 5 copies of the same string
  • To join two strings/variables
  • To Split a string on a given character
  • To replace only first occurrence of string 
  • To replace only all occurrences of string 
  • To find the length of the string
  • To extract a substring from a string
  • To uppercase a string
  • To lowercase a string
  • To redirect the standard output of a command to a file
  • To redirect the standard error of a command to a file
  • To redirect both standard output and error of a command to a file
  • To discard standard output of a command to a file
  • To discard standard error of a command to a file
  • To discard standard output and error of a command to a file
  • To redirect contents of a files to the standard input of a command 
  • To redirect list of strings i.e. multiline to the standard input of a command 
  • To redirect a single line of text to the standard input of a command 
  • To redirect standard output of all command 
  • To redirect standard error of all command 
  • To redirect standard output and error of all command 
  • To send the output from multiple commands to a file
  • To use exec command in script to capture all standard error and standard output  in separate file 
  • To prevent overwriting the contents of a file when redirecting output
  • To redirect standard input to a file and print it to standard output
  • To send standard output of one command to standard input of another command
  • To send standard output and error of one command to standard input of another command
  • How order of redirection matters
  • To swap standard output and standard error
  • To send standard output to one command and standard error to another command
  • To find the exit codes of all piped commands
  • To erase all shell history
  • To stop logging history for this session
  • To change log file for capturing command history 
  • To add timestamp to history logs
  • To show history
  • To repeat last executed command
  • To execute the most recent command starting with the given string
  • To open the previous command you executed in a text editor
  • Use short-keys on shell prompt to move to beginning of the line
  • Use short-keys on shell prompt to move to end of the line
  • Use short-keys on shell prompt to move the cursor “one word” backward
  • Use short-keys on shell prompt to move the cursor “one word” forward
  • Use short-keys on shell prompt to delete “last word”
  • Use short-keys on shell prompt to undo recently deleted “last word”
  • Use short-keys on shell prompt to move the cursor “one character” backward
  • Use short-keys on shell prompt to move the cursor “one character” forward
  • Use short-keys on shell prompt to delete “whole line”
  • Use short-keys on shell prompt to search the history backward
  • Use short-keys on shell prompt to search the history forward
  • Use short-keys on shell prompt to swap “two adjacent characters” 
  • Use short-keys on shell prompt to swap “two adjacent words” 
  • Use short-keys on shell prompt to convert characters next to cursor location in a word to uppercase 
  • Use short-keys on shell prompt to convert characters next to cursor location in a word to lowercase 
  • Use short-keys on shell prompt to capitalized a character in a word
  • Use short-keys on shell prompt to comment the current line (i.e. append # at the beginning quickly)
  • Use short-keys on shell prompt to delete “one character” to the left
  • Use short-keys on shell prompt to delete “one character” to the right
  • Use short-keys on shell prompt to comment the current line (i.e. append # at the beginning quickly)
  • Use short-keys on shell prompt to undo last action 
  • Use short-keys on shell prompt to undo all changes to a line
  • Use short-keys on shell prompt to clear screen
  • To list CRON jobs for a user
  • To edit CRON jobs for a user
  • To schedule a job which will run every minute for capturing number of processes running for each user on system
  • To schedule a job which will run on each 12 min for capturing number of open files on system for against each user 
  • To schedule a job which will run hourly for capturing user’s logged in at that moment
  • To schedule a job which will run twice in a day for checking filesystem utilization and through alert for utilization more than 40%
  • To schedule a job which will run alternate day at 9 AM for backup of a directory by keeping latest 3 copies including current one
  • To schedule a job which will run each alternate Sunday for calculating top 10 users having home directory usage high.
  • To schedule a job which will run on first minute of each year to capture uptime of system
  • To print date in terminal default format
  • To print Date in terminal GMT/UTC time zone
  • To set a date
  • To display Month, Day and Year
  • To display Hours, Minutes and Seconds
  • To find the number of seconds from unix epoch.
  • To display date with customized text
  • To execute a job in the background and get it in foreground again (dependent on current session)
  • To execute a job in the background and get it in foreground again (not dependent on current session)
  • To display calendar of Sept, 1972 
  • To display calendar of first three months of 2008
  • To display calendar of complete year 1999
  • To toggle between the last two directories cd -
  • To go to home directory cd ~
  • To check permissions summary for a folder i.e. list of possible users, group and permissions with count of each possibility

Home

No comments:

Post a Comment