Current working directory - pwd
To find out where your home directory is in relationship to the rest of the filesystem, you can use the pwd command. This command displays the directory that we are currently in.
$ pwd
List information about the files - ls
To display the directory that you are in, you use "ls" command.
$ ls
For instance, to list all of the contents in an extended form, we can use the -lflag (for "long" output):
$ ls -l
Change the working directory - cd
Begin by going back to the mydirectory directory by typing this:
$ cd mydirectory
You can use absolute or relative path.
Viewing a file - cat
Use the "cat" command for read the contents of a file. This command concatenates one or more files to standard output. Example:
$ cat myfile.txt
Create a file - touch
The "touch" command creates a file in your filesystem. Example:
$ touch myfile.txt
Create a directory - mkdir
The "mkdir" command creates a new directory in your filesystem. Example:
$ mkdir mydirectory
To tell mkdir that it should create any directories necessary to construct a given directory path, you can use the -p option
$ mkdir -p dir1/dir2/mydirectory
Moving and Renaming Files and Directories - mv
You can move a file to a new location using the mv command. For example, you can move myfile into the dir1 directory by typing:
$ mv myfile dir1
So to rename the dir1 directory to directory1:
$ mv dir1 directory1
Copy files and directories - cp
The cp command can make a new copy of an existing file or directory. For example, you can copy myfile.txt into same directory but with a different name (myfile2.txt):
$ cp myfile.txt myfile2.txt
Instead if you can copy a directory, use "-r" option:
$ cp -r mydir new_mydir
Remove a file - rm
The rm command remove a file. For example, you can remove myfile2.txt with the following command:
$ rm myfile2.txt
Remove a directory - rmdir
The rmdir command remove a directory. For example, you can remove new_mydir with the following command:
Alternatively you can use the following command:
$ rmdir new_mydir
$ rm -r new_mydir
Remove all files (recursively)
You can remove recursively all files with a precise name (or regular expression) from a specific path. Example: you can remove all .svn files from a your workspace, so you can execute the following command into workspace directory:
$ find . -name .svn -exec rm -rf {} \;
$ find . -name .svn -exec rm -rf {} \;
Find all snapshot version in a maven project
$ find . -name pom.xml | xargs grep "SNAPSHOT"
$ find . -name pom.xml | xargs grep "SNAPSHOT"
Disk Usage - du
$ du -h
No comments:
Post a Comment