Showing posts with label command. Show all posts
Showing posts with label command. Show all posts

8/24/2015

Linux: Which command shell am I using

To see which shell you are using you can enter a command like:

echo $SHELL

Or maybe go look in the user password file:

cat /etc/passwd
which may return:

/bin/bash 

 which will return a bunch of lines, along with one that is your username:

myusername:x:1000:1000:My,Name,999-999-9999,:/home/folder:/bin/bash

both of which tell me that I'm using the BASH shell.

3/26/2014

Linux: Find files by name

To find a file by name on Linux, you use the find command with the -name flag:

For example, you might want to find the location of the Apache configuration file.

To start at the top, root directory, you would type:
find / -name httpd.conf

Linux: Copy files and folders recursively

Say you want to copy a directory (a folder) and all of its contents to a different directory. AND it contains subdirectories
OLD LOCATION : /2013_records/
NEW LOCATION: ../someNewPathHere/archive/2013_records/
If you try to use the cp command, you may see that the subdirectories are not being copies.
cp 2013_records/* ../someNewPathHere/archive/2013_records/
You will probably get an "error" like this, and nothing happens:
cp: omitting directory '2013_records'
You should add a few flags to your cp command:
-a = archive (meaning keep all of the timestamp and ownership info)
-v = verbose (meaning, show me what you're doing.)
-r = recursively (meaning everything below the top level)
So, the correct copy command should have been.
cp -avr 2013_records/* ../someNewPathHere/archive/2013_records/

5/26/2013

Linux: How to remove folders that are not empty? Delete directories recursively?

There is a Linux shell command to remove a directory: rmdir.
rmdir /path/to/nameOfDirectory
However, it will not remove directories that have not be emptied already.

You can remove a directory that still has files and subdirectories, but it is a little dangerous.
So, be careful when you use the rm command in this manner.
rm -rf /path/to/filenameYouWantToDelete
The -r option means to do it recursively (referring to the hierarchical content inside of subdirectories).

The -f option means to "force" or ignore nonexistent files, without prompts.

5/25/2013

Linux: Find files that have been Changed, Modified or Accessed recently? List from last minutes or days?

The command to locate and list files that have been modified, changed or accessed recently is "find".

"Find" can be used in combination with tests that begin with "a", "c" or "m" for Access, Change or Modify.
And either "min" for minutes or "time" for days.

Ex.
To find any files that have been changed in the last two days
find . -ctime -2 
To find any .php files that have been modified in the last 2 hours:
find *.php -mmin -120
To find any files that have been accessed in the past 3 days, but not including today: 
find . -atime +0 -a -atime -3
The minus (-) before the number value means "within the past number of days / minutes."
The plus (+) before the number value means  "before the past number of days / minutes."
The last example joins two commands, to mean "any time before today, and within the last 3 days."

You'll probably want to pipe long lists of results to a "more" command.

Ex.
find . -ctime -2 | more

Linux: How can I page output of results? Stop long lists of filenames, text read out?

The way to make long lists of output easier to read on screen, is to pipe the result to the  "more" command.
ex.
myRequest | more
In the real world you might want a detailed list of the contents of a directory that has a lot of files. You could use:
ls -la | more
At the bottom of the screen you'll probably see an indicator in reverse color, that reads "--More--".

To see the next line, you can hit the [Enter] key on your keyboard.

To see the next page of results, you can hit the [Spacebar] on your keyboard.

To stop the list from displaying further, or to break out of the command, you can hold [Ctrl] key and hit [C].

Linux: How to time that file was Changed, Modified or Accessed?

The Linux shell command to see or retrieve what time a file was changed is "stat".
ex. 
stat yourFileName.here
 [yourPrompt]# stat yourFileName.here
  File: `yourFileName.here'
  Size: 219             Blocks: 8          IO Block: 4096   regular file
Device: dh/3d  Inode: 30229777    Links: 1
Access: (0644/-rw-r--r--)  Uid: (  500/ownerName)   Gid: (  500/groupName)
Access: 2010-04-26 13:13:59.000000000 -0400
Modify: 2010-04-26 13:13:59.000000000 -0400
Change: 2013-05-24 18:04:27.000000000 -0400

You can also get results for multiple files using standard shortcut conventions.
ex. 
stat yourFile*
In this case, the stat command reveals that someone Changed a file yesterday, but the Modify and Access dates were not changed. 

Very clever bad boys out there....

Apparently, one may change the modification  date by using the "touch" command.