Skip to main content

Posts

Hiding a file or directory under Linux

Hiding a file or directory under Linux To hide a file or directory in Linux, just give it a name preceded by a full stop (.). For example: . bash_history . bash_profile . ssh    Hide UNIX file structure   1. Open a terminal and execut "ls -1 / | sudo tee /.hidden" 2. Do "sudo chmod a+r .hidden" 3. If you want all standard files hidden, skip to 5. Otherwise. Open the file with "sudo gedit /.hidden". 4. Remove every directory you don't want to hide from the file. Here's how mine looks like, as an example: bin boot opt usr etc sys tmp srv proc root sbin lib lost+found mnt initrd dev debootstrap var cdrom initrd.img initrd.img.old vmlinuz vmlinuz.old home media 5. Now, let's create some entries that are easier for new users: select "home" and create a link to link to it (for example, by dragging it and holding <ctrl>+<shift>. Your mouse cursor shou...

Touch & More

Touch touch [-acm] [-f agefile] [-r agefile] [[-t] time] file ... touch [-acm] time file ... DESCRIPTION The touch command changes certain dates for each file argument. By default, touch sets both the date of last file modification and the date of last file access to the current time. This is useful for maintaining correct release times for software and is particularly useful in conjunction with the MKS Make software development facility. Options -a     sets only the access time. -c     does not create any files that do not already exist. Normally, touch creates such files. -m     sets only the modification time. If you do not specify -a or -m, touch behaves as though you specified both. To tell touch to use a time other than the current, use one of the following options: -f agefile    is an obsolete version of the POSIX-compliant -r option. -r agefile   ...

Beginners UNIX Interview Questions Answers

1. Write command to list all the links from a directory? In this UNIX command interview questions interviewer is generally checking whether user knows basic use of "ls" "grep" and regular expression etc You can write command like: ls -lrt | grep "^l" 2. Create a read-only file in your home directory? This is a simple UNIX command interview questions where you need to create a file and change its parameter to read-only by using chmod command you can also change your umask to create read only file. touch file chmod 400 file 3. How will you find which operating system your system is running on in UNIX? By using command "uname -a" in UNIX 4. How will you run a process in background? How will you bring that into foreground and how will you kill that process? For running a process in background use "&" in command line. For bringing it back in foreground use command "fg jobid" and for getting j...

Basic shell scripting part 3

1. What is Shell Scripting ?         Shell scripting, in Linux or Unix,  is programming with the shell using which you can automate your tasks. A shell is the command interpreter which is the interface between the User and the kernel. A shell script allows you to submit a set of commands to the kernel in a batch. In addition, the shell itself is very powerful with many properties on its own, be it for string manipulation or some basic programming stuff.  2. The command "cat file" gives error message "--bash: cat: Command not found". Why?     It is because the PATH variable is corrupt or not set appropriately. And hence the error because the cat command is not available in the directories present PATH variable. 3. How to find the length of a string  in Linux? $ x="welcome" $ echo ${#x} 7 4. What are the different timestamps associated with a file? Modification time:- Refers to the time when the file is last modifie...

Basic shell scripting part 2

How do you find out what’s your shell? Answer: echo $SHELL What’s the command to find out today’s date? Answer: date  What’s the command to find out users on the system? Answer: who How do you find out the current directory you’re in? Answer: pwd How do you remove a file? Answer: rm How do you remove a file? Answer: rm -rf How do you find out your own username? Answer: whoami How do you send a mail message to somebody? Answer: mail somebody@techinterviews.com -s ‘Your subject’ -c ‘ cc@techinterviews.com ‘ How do you count words, lines and characters in a file? Answer: wc How do you search for a string inside a given file? Answer: grep string filename How do you search for a string inside a directory? Answer: grep string * How do you search for a string in a directory with the subdirectories recursed? Answer: grep -r string * What are PIDs? Answer: They are process IDs given to processes. A PID can vary from 0 to 65535. How do you list c...

Basic shell scripting part 1

What is $*? Its mainly used for showing up all params. This show all parameter values passed in shell script What does $# stand for? # will return the number of parameters that are passed as the command-line arguments. What does $? Return? $? will return exit status of command .0 if command gets successfully executed ,non-zero if command failed. What are Different types of shells? sh : the oldest shell  csh : C shell  ksh : Korn Shell  bash : bourne again shell  How do you read arguments in a shell program – $1, $2? Shell script accepts parameters in following format…  $1 would be the first command line argument, $2 the second, and so on  $0 is the name of the script or function If your script has more than 9 params then accept in following way…  ${12} : 12th param  ${18} : 18th param What are the different kinds of loops available in shell script ? for, if, while, case What is the difference...

Unix questions with answers

This article attempts to refresh your Unix skills in the form of a question/answer based Unix tutorial on Unix command lines. The commands discussed here are particulary useful for the developers working in the middle-tier (e.g. ETL) systems, where they may need to interact with several *nx source systems for data retrieval. How to print/display the first line of a file? There are many ways to do this. However the easiest way to display the first line of a file is using the [head] command. $> head -1 file.txt No prize in guessing that if you specify [head -2] then it would print first 2 records of the file. Another way can be by using [sed] command. [Sed] is a very powerful text editor which can be used for various text manipulation purposes like this. $> sed '2,$ d' file.txt How does the above command work? The 'd' parameter basically tells [sed] to delete all the records from display from line 2 to last line of the file (last line is represented by $ ...