Apptya
Welcome to our FREE online Linux tutorials for beginners! You will find many Linux help tutorials here and the beginner Linux tutorial will constantly be updated. There is always new Linux software being developed and added into this awesome opensource Unix-based operating system that will need tutorials and guides written for beginners.
Even though beginner Linux tutorials will be geared towards Linux beginners, we will also have plenty of help here as well for those advanced Linux users. I myself have been using Linux since around 1996 maybe? I do consider myself a Linux guru or advanced user, but even I need to look up Linux tutorials, Linux how-tos, or maybe even Linux hardware compatibility. There is constantly new hardware coming out everyday and most computer hardware manufacturers don’t make drivers for Linux. What do you do? Jump on your favorite search engine and look for what modules to load or maybe what configuration file needs edited. Which with some of the new Linux software in today’s world, most hardware is auto-detected.
Hope you enjoy your stay at beginner Linux tutorials and that you find the Linux tutorials very helpful even if you are an advanced Linux user. Which by the way if you are an advanced Linux user and want to help contribute some tutorials for Linux beginners please let me know! I would appreciate it very much to get some more writers to help get more users away from the evil Microsoft products by making it easier for the Linux beginners to understand and operate the Linux operating system.
Friday, July 16, 2010
Linux chown Command Change Owner
The Linux chown command is used to change the owner and group of a file or directory. If you have a directory and you are not the owner and would like to be the owner of that directory, you can use the Linux chown command to change the owner to your username.
Some of you may get a lot of permission denied errors while trying to open files or folders, this may be caused by improper ownership or owner permissions. If it is a ownership problem,
chown will fix your problem. If it is a permission problem, then you will want to look into chmod.
The usage of chown is chown [OPTIONS] [OWNER]:[GROUP] [FILE]. There are many options for chown, but I only use 2 of them on a regular basis. I use chown -R | --recursive and also chown --from=CURRENT_OWNER:CURRENT_GROUP. Basically chown -R is used on directories and all files in that directory. chown --from=CURRENT_OWNER:CURRENT_GROUP is used if you want to only change files that are currently owned by CURRENT_OWNER:CURRENT_GROUP.
For some examples of the Linux chown command. Say I have a desktop computer with Linux on it, and my username on the desktop computer is BrandonStimmel, and I buy a new laptop and install Linux on it, and this time I made my username Brandon. I also want to get rid of my desktop because it is slow and uses a lot of electricity. So I want to copy all of my files and folders from the desktop’s /home/BrandonStimmel to the laptop’s /home/Brandon. I simply use rsync, cp, or scp to copy the files and folders from the desktop computer to the laptop computer. Trouble is, I can only read files, I can’t write to them. I keep getting permission denied errors, and you don’t have permission to write to the file $FILE. So I login to the laptop as my user, then su to root, since root has permissions to read and write to the files/folders. Then I run chown -R --from=BrandonStimmel:users Brandon:users /home/Brandon/* Some may ask why I used chown --from= in this example. Well I have a ton of files in my home folder from my desktop and I may have some files that were meant to be owned by root, or some other user as backups. I didn’t want to change all of them to my new username unless I owned them before.
If you use the same example but don’t care who previously owned the files/folders, you can run chown -R Brandon:users /home/Brandon/* and you will change all files/folders in /home/Brandon to be owned by the username Brandon and the group users.
I hope this Linux tutorial on the Linux chown command has helped you fix your permission issues. If you have any questions please feel free to contact Beginner Linux Tutorial by leaving a comment or sending an email. Have a great day and remember to read more Linux tutorials! Knowledge is power, especially with Linux!
Some of you may get a lot of permission denied errors while trying to open files or folders, this may be caused by improper ownership or owner permissions. If it is a ownership problem,
chown will fix your problem. If it is a permission problem, then you will want to look into chmod.
The usage of chown is chown [OPTIONS] [OWNER]:[GROUP] [FILE]. There are many options for chown, but I only use 2 of them on a regular basis. I use chown -R | --recursive and also chown --from=CURRENT_OWNER:CURRENT_GROUP. Basically chown -R is used on directories and all files in that directory. chown --from=CURRENT_OWNER:CURRENT_GROUP is used if you want to only change files that are currently owned by CURRENT_OWNER:CURRENT_GROUP.
For some examples of the Linux chown command. Say I have a desktop computer with Linux on it, and my username on the desktop computer is BrandonStimmel, and I buy a new laptop and install Linux on it, and this time I made my username Brandon. I also want to get rid of my desktop because it is slow and uses a lot of electricity. So I want to copy all of my files and folders from the desktop’s /home/BrandonStimmel to the laptop’s /home/Brandon. I simply use rsync, cp, or scp to copy the files and folders from the desktop computer to the laptop computer. Trouble is, I can only read files, I can’t write to them. I keep getting permission denied errors, and you don’t have permission to write to the file $FILE. So I login to the laptop as my user, then su to root, since root has permissions to read and write to the files/folders. Then I run chown -R --from=BrandonStimmel:users Brandon:users /home/Brandon/* Some may ask why I used chown --from= in this example. Well I have a ton of files in my home folder from my desktop and I may have some files that were meant to be owned by root, or some other user as backups. I didn’t want to change all of them to my new username unless I owned them before.
If you use the same example but don’t care who previously owned the files/folders, you can run chown -R Brandon:users /home/Brandon/* and you will change all files/folders in /home/Brandon to be owned by the username Brandon and the group users.
I hope this Linux tutorial on the Linux chown command has helped you fix your permission issues. If you have any questions please feel free to contact Beginner Linux Tutorial by leaving a comment or sending an email. Have a great day and remember to read more Linux tutorials! Knowledge is power, especially with Linux!
Linux more and less Commands
The Linux commands more and less are similar to cat, but with more and less you can scroll the file instead of showing the enter file at once. So if you have larger files you want to view that are longer than your screen or terminal then you can use more or less commands instead of cat.
I would suggest using less more often than more as the Linux less command can load files to the screen faster. If you do more somefile.txt the entire file must be read before it will start displaying on your screen. If you use less somefile.txt the contents of somefile.txt will be displayed as they are read from the file, so you don’t have to wait until the entire contents are read before you can see it!
Another reason I would suggest using the Linux command less more than the Linux command more is because with less command you can scroll up in the file as well as down, where with the Linux command more you can only scroll down the file. If you pass something with more you have to quit, run the more command again, and hope you don’t pass what you were looking for again.
The syntax for more is like most Linux commands: more [OPTIONS] [filename]. The sytax for less is the same: less [OPTIONS] [FILENAME].
The only options I use normally with less is less -N [FILENAME] which will print line numbers before each line. The only options I use on more is more +[number] [FILENAME] which will start you on line [number].
Now for some examples of more.
If I wanted to view file phone-numbers.txt to write them down on paper, or enter into my cellphone, I could run more phone-numbers.txt and hit enter to scroll down after I have already entered the information on my cellphone or wrote them down on paper.
If I was working on a php/mysql website and I click on Login which takes me to login.php and I get something like: PHP parse error : syntax error, unexpected T-STRING on line 130 in file /home/user/www/login.php I can then run more +130 /home/user/www/login.php which will start me on line 130 where the error is so I can look for what is wrong and then fix it.
Now for some examples of less.
If I was working on a php/mysql website and I was writing a foreach() loop on my php script and needed a little help from someone that has a copy of my script, I could do less -N some-script.php and tell him or her what lines I was having problems with.
Well that’s it for the Linux more and less commands. As always I hope this Linux tutorial on the Linux less and more commands has helped you understand more and less a bit more! Thank you for reading my Linux tutorials on Beginner Linux Tutorial, I hope you have a great day! Any questions of problems with more or less can be asked below in the comment section.
I would suggest using less more often than more as the Linux less command can load files to the screen faster. If you do more somefile.txt the entire file must be read before it will start displaying on your screen. If you use less somefile.txt the contents of somefile.txt will be displayed as they are read from the file, so you don’t have to wait until the entire contents are read before you can see it!
Another reason I would suggest using the Linux command less more than the Linux command more is because with less command you can scroll up in the file as well as down, where with the Linux command more you can only scroll down the file. If you pass something with more you have to quit, run the more command again, and hope you don’t pass what you were looking for again.
The syntax for more is like most Linux commands: more [OPTIONS] [filename]. The sytax for less is the same: less [OPTIONS] [FILENAME].
The only options I use normally with less is less -N [FILENAME] which will print line numbers before each line. The only options I use on more is more +[number] [FILENAME] which will start you on line [number].
Now for some examples of more.
If I wanted to view file phone-numbers.txt to write them down on paper, or enter into my cellphone, I could run more phone-numbers.txt and hit enter to scroll down after I have already entered the information on my cellphone or wrote them down on paper.
If I was working on a php/mysql website and I click on Login which takes me to login.php and I get something like: PHP parse error : syntax error, unexpected T-STRING on line 130 in file /home/user/www/login.php I can then run more +130 /home/user/www/login.php which will start me on line 130 where the error is so I can look for what is wrong and then fix it.
Now for some examples of less.
If I was working on a php/mysql website and I was writing a foreach() loop on my php script and needed a little help from someone that has a copy of my script, I could do less -N some-script.php and tell him or her what lines I was having problems with.
Well that’s it for the Linux more and less commands. As always I hope this Linux tutorial on the Linux less and more commands has helped you understand more and less a bit more! Thank you for reading my Linux tutorials on Beginner Linux Tutorial, I hope you have a great day! Any questions of problems with more or less can be asked below in the comment section.
Linux grep Command
The Linux grep command is used to extract lines of data from files or extract data from other Linux commands by using a pipe. When using the Linux grep command, there are many ways you can extract or print lines. You can use standard text to grep or you can use regex patterns. When using regex patterns you can use basic regular expression (BRE),
extended regular expression (ERE), or even a Perl regular expression!
There are many different grep options you can use in the grepsyntax. I myself only use a few options with grep on a regular basis. The basic grep syntax is grep [options] [pattern] [file|files].
grep quick reference guide:
You can use grep -R, grep -r, grep --recursive, which will allow you to have grep parse files recursivley into other directories.
If you are working with code, or just want the output lines to be numbered you can use grep -n or grep --line-number.
Another option I use on a daily basis with grep is grep -i or grep --ignore-case, which will ignore case on both the input file, and the pattern. by default grep is case sensitive, so you have to use this option if you do not want it case sensitive.
If you are wanting to extract multiple patterns from your file, you can use grep -e which can be used multiple times to extract multiple patterns from your file. So if you are wanting to grep two different strings from one file in Linux, you could do grep -e firstpattern -e secondpattern /home/$USER/file.txt.
Here are some grep examples of using the Linux grep command:
If I had a plain text file called phone-book.txt, that had phone numbers listed in this order: First Name Last Name - Street Address - Phone Number
Now I want to get Brandon Stimmel’s phone number. I could rungrep Brandon\ Stimmel phone-book.txt and grep would print Brandon Stimmel - 100101 Digital Ave. Tech, Ohio 44333 (330) 222-7222. Notice I used Brandon\ Stimmel, I did this because you can not use a space on the command line, or it will be parsed as the next section of the command, which grep Brandon Stimmel phone-book.txtwithout the \ would try to extract Brandon from the file Stimmel, which doesn’t exist. So remember to escape your spaces with a \ if you are using them in your pattern/search string.
For another example, if I want to bring up who owns the phone number (330) 222-7222 as it showed up on my caller ID, but I forgot who’s phone number it was, I can do grep \(330\)\ 222-7222 phone-book.txt which would again display: Brandon Stimmel - 100101 Digital Ave. Tech, Ohio 44333 (330) 222-7222.
You can also grep for just the last name, say if you are having a family reunion and you want to bring up all of the people with the last name of Stimmel. grep Stimmel phone-book.txt this will bring up every person in phone-book.txt that has the last name of Stimmel.
You can also pipe data to grep or pipe data from grep to use it in a bash script. Say if you are wanting to do the above example that you found a phone number and forgot who’s it was, but you don’t want to show the entire line with name, address, and number, you just want the name and only the name. grep \(330\)\ 222-7222 phone-book.txt|awk '{print $1" "$2}' which will outputBrandon Stimmel. The grep part of this code will output the full string, then we pass that data onto awk which we used it to print only the first and second fields
extended regular expression (ERE), or even a Perl regular expression!
There are many different grep options you can use in the grepsyntax. I myself only use a few options with grep on a regular basis. The basic grep syntax is grep [options] [pattern] [file|files].
grep quick reference guide:
You can use grep -R, grep -r, grep --recursive, which will allow you to have grep parse files recursivley into other directories.
If you are working with code, or just want the output lines to be numbered you can use grep -n or grep --line-number.
Another option I use on a daily basis with grep is grep -i or grep --ignore-case, which will ignore case on both the input file, and the pattern. by default grep is case sensitive, so you have to use this option if you do not want it case sensitive.
If you are wanting to extract multiple patterns from your file, you can use grep -e which can be used multiple times to extract multiple patterns from your file. So if you are wanting to grep two different strings from one file in Linux, you could do grep -e firstpattern -e secondpattern /home/$USER/file.txt.
Here are some grep examples of using the Linux grep command:
If I had a plain text file called phone-book.txt, that had phone numbers listed in this order: First Name Last Name - Street Address - Phone Number
Now I want to get Brandon Stimmel’s phone number. I could rungrep Brandon\ Stimmel phone-book.txt and grep would print Brandon Stimmel - 100101 Digital Ave. Tech, Ohio 44333 (330) 222-7222. Notice I used Brandon\ Stimmel, I did this because you can not use a space on the command line, or it will be parsed as the next section of the command, which grep Brandon Stimmel phone-book.txtwithout the \ would try to extract Brandon from the file Stimmel, which doesn’t exist. So remember to escape your spaces with a \ if you are using them in your pattern/search string.
For another example, if I want to bring up who owns the phone number (330) 222-7222 as it showed up on my caller ID, but I forgot who’s phone number it was, I can do grep \(330\)\ 222-7222 phone-book.txt which would again display: Brandon Stimmel - 100101 Digital Ave. Tech, Ohio 44333 (330) 222-7222.
You can also grep for just the last name, say if you are having a family reunion and you want to bring up all of the people with the last name of Stimmel. grep Stimmel phone-book.txt this will bring up every person in phone-book.txt that has the last name of Stimmel.
You can also pipe data to grep or pipe data from grep to use it in a bash script. Say if you are wanting to do the above example that you found a phone number and forgot who’s it was, but you don’t want to show the entire line with name, address, and number, you just want the name and only the name. grep \(330\)\ 222-7222 phone-book.txt|awk '{print $1" "$2}' which will outputBrandon Stimmel. The grep part of this code will output the full string, then we pass that data onto awk which we used it to print only the first and second fields
Linux cat Command
Linux cat Command
In this Linux tutorial you will learn how to use the Linux cat command. The Linux cat command is the Unix command to list a file’s contents onto your screen, or pass via pipeline to use with other Linux commands. The cat command comes from the word concatenate.
The usage of the Linux cat command is cat
[options] [file].
There are quite a few options you can use with the Linux cat command, but I rarely use any of them on a regular basis. The only option I use with the cat command on a regular basis is cat -n or cat --number.
For an example of using the cat command, we’ll say I have a file named Linux-Friends.txt and in this text file I have some friend’s names, phone numbers, and e-mail addresses that run Linux. So now I want to get someone’s phone number from this list. I can run cat Linux-Friends.txt in a Linux terminal and I will get the contents of this file listed on my screen.
Now if I wanted to see how many friends I have listed in this file, I can have cat number the lines for me by using the cat -n option. So if I run cat -n Linux-Friends.txt the cat command will then output each of the Linux friend’s that I have listed and place a number in front of each one so I can see how many friends I have. Using cat -n [file] is also useful when doing some programming or coding, so you can see what line number you need to edit.
You can also pipe off of the Linux cat command to use it with other Linux commands. So for this example of the Linux cat command I want to only grab a certain person’s name from the list to display their contact information. So I can run cat Linux-Friends.txt|grep Brandon and now I will only get Brandon’s contact information.
Another example of using the Linux cat command with other Linux commands via pipe is if I only want Brandon’s email address to display and not his phone number. The Linux-Friends.txt file is in this format: last name, first name – phone number – email address so I can use the Linux cat command with grep and also awk to display only what I want. So I can run cat Linux-Friends.txt|grep Brandon|awk '{print $4" "$5}' and now I have Brandon’s phone number.
For an explaination of the command above I will show each output as each command is ran.
cat Linux-Friends.txt
–friend 1,2,3–
Stimmel, Brandon – (330) 222-7222 – news@beginnerlinuxtutorial.com
–friend 5,6,7–
Now we add |grep Brandon
Stimmel, Brandon – (330) 222-7222 – news@beginnerlinuxtutorial.com
and you see the other friends are now gone. Now we can add |awk '{print $4" "$5}' which will display the 4th and 5th column, and the – in that file counts as a column as well. The 4th column is (330) and the 5th column is 222-7222. So my output now would be: (330) 222-7222
In this Linux tutorial you will learn how to use the Linux cat command. The Linux cat command is the Unix command to list a file’s contents onto your screen, or pass via pipeline to use with other Linux commands. The cat command comes from the word concatenate.
The usage of the Linux cat command is cat
[options] [file].
There are quite a few options you can use with the Linux cat command, but I rarely use any of them on a regular basis. The only option I use with the cat command on a regular basis is cat -n or cat --number.
For an example of using the cat command, we’ll say I have a file named Linux-Friends.txt and in this text file I have some friend’s names, phone numbers, and e-mail addresses that run Linux. So now I want to get someone’s phone number from this list. I can run cat Linux-Friends.txt in a Linux terminal and I will get the contents of this file listed on my screen.
Now if I wanted to see how many friends I have listed in this file, I can have cat number the lines for me by using the cat -n option. So if I run cat -n Linux-Friends.txt the cat command will then output each of the Linux friend’s that I have listed and place a number in front of each one so I can see how many friends I have. Using cat -n [file] is also useful when doing some programming or coding, so you can see what line number you need to edit.
You can also pipe off of the Linux cat command to use it with other Linux commands. So for this example of the Linux cat command I want to only grab a certain person’s name from the list to display their contact information. So I can run cat Linux-Friends.txt|grep Brandon and now I will only get Brandon’s contact information.
Another example of using the Linux cat command with other Linux commands via pipe is if I only want Brandon’s email address to display and not his phone number. The Linux-Friends.txt file is in this format: last name, first name – phone number – email address so I can use the Linux cat command with grep and also awk to display only what I want. So I can run cat Linux-Friends.txt|grep Brandon|awk '{print $4" "$5}' and now I have Brandon’s phone number.
For an explaination of the command above I will show each output as each command is ran.
cat Linux-Friends.txt
–friend 1,2,3–
Stimmel, Brandon – (330) 222-7222 – news@beginnerlinuxtutorial.com
–friend 5,6,7–
Now we add |grep Brandon
Stimmel, Brandon – (330) 222-7222 – news@beginnerlinuxtutorial.com
and you see the other friends are now gone. Now we can add |awk '{print $4" "$5}' which will display the 4th and 5th column, and the – in that file counts as a column as well. The 4th column is (330) and the 5th column is 222-7222. So my output now would be: (330) 222-7222
How to Delete in Linux Terminal rm Command
Many Linux users get confused when they are in a Linux terminal and trying to delete files of folders. So in this Linux tutorial, I will cover how to delete files in Linux terminal! The Linux delete command is another basic command that is used everyday while in a Linux terminal. There are only 2 options that I use on a regular basis with the Linux rm
command.
The usage of the Linux rm command is rm [options] [file|dir]. The 2 options I use most is rm -r [dir] and rm -f [file]. Now to explain these options for the Linux delete command and also give you some examples on how to remove a file with Linux.
The rm -f [file] option is if you are wanting to force a file to be removed. This will not ask you “are you sure you want to remove [file]“. It will just delete the file regardless. So use this option for the Linux rm command only if you know you want all of the file(s) deleted.
Now the rm -r [dir] option is if you are wanting to delete a directory in Linux. The rm -r option is to specify to remove recursively, meaning a directory and it’s contents.
You can use these 2 options for the Linux delete command together as well. You could use the command rm -rf [dir] to delete a directory forcefully and recursively. DO NOT be fooled into running rm -rf /, rm -rf /* as this will remove all of your files and folders. Some people may come off as they are trying to help you with Linux and be a dick and tell you to run rm -rf /* which you can then say bye bye to your files and folders.
You can also use rm in a script type command after a pipe | so you can delete filenames of the output. You can also use rm to remove files that are produced from another command or script. Here is an example of how to remove a file found after grep in Linux. Say if you have a folder /home/max/images/family and in this directory you have 20 images that have the word copy in the title because you accidentally highlighted these 20 files, went to drag them into another folder in a GUI, and let go too early and created copies. So now you want to remove these copies, you would first cd to that directory cd /home/max/images/family now you can run rm -f `ls | grep copy` which will remove all the files that ls | grep copy matches. This same process could be done easier by running rm -f *copy* instead, but these are just examples.
I hope reading this Linux tutorial on the Linux rm command has taught you more than you already know and that you can continue reading through this Beginner Linux Tutorial website and learn even more about the Linux operating system! Have a great day and remember DO NOT run rm -rf /* or any variation of it. I will write a section on Beginner Linux Tutorial explaining more of the commands that can harm your system to watch out for when people are trying to help you with Linux so that you will not be a victim of this. If you are unsure if a command will harm your system, you can always do a quick reference check by searching the net for that command, or even looking at the man pages for that command to see what it is that command/options will do. You can read your manpages by typing man [command] like man rm will bring up the manual for the Linux rm command.
command.
The usage of the Linux rm command is rm [options] [file|dir]. The 2 options I use most is rm -r [dir] and rm -f [file]. Now to explain these options for the Linux delete command and also give you some examples on how to remove a file with Linux.
The rm -f [file] option is if you are wanting to force a file to be removed. This will not ask you “are you sure you want to remove [file]“. It will just delete the file regardless. So use this option for the Linux rm command only if you know you want all of the file(s) deleted.
Now the rm -r [dir] option is if you are wanting to delete a directory in Linux. The rm -r option is to specify to remove recursively, meaning a directory and it’s contents.
You can use these 2 options for the Linux delete command together as well. You could use the command rm -rf [dir] to delete a directory forcefully and recursively. DO NOT be fooled into running rm -rf /, rm -rf /* as this will remove all of your files and folders. Some people may come off as they are trying to help you with Linux and be a dick and tell you to run rm -rf /* which you can then say bye bye to your files and folders.
You can also use rm in a script type command after a pipe | so you can delete filenames of the output. You can also use rm to remove files that are produced from another command or script. Here is an example of how to remove a file found after grep in Linux. Say if you have a folder /home/max/images/family and in this directory you have 20 images that have the word copy in the title because you accidentally highlighted these 20 files, went to drag them into another folder in a GUI, and let go too early and created copies. So now you want to remove these copies, you would first cd to that directory cd /home/max/images/family now you can run rm -f `ls | grep copy` which will remove all the files that ls | grep copy matches. This same process could be done easier by running rm -f *copy* instead, but these are just examples.
I hope reading this Linux tutorial on the Linux rm command has taught you more than you already know and that you can continue reading through this Beginner Linux Tutorial website and learn even more about the Linux operating system! Have a great day and remember DO NOT run rm -rf /* or any variation of it. I will write a section on Beginner Linux Tutorial explaining more of the commands that can harm your system to watch out for when people are trying to help you with Linux so that you will not be a victim of this. If you are unsure if a command will harm your system, you can always do a quick reference check by searching the net for that command, or even looking at the man pages for that command to see what it is that command/options will do. You can read your manpages by typing man [command] like man rm will bring up the manual for the Linux rm command.
How to Move Files in Linux mv Command
If you are wanting to know how to move files in Linux, you will need to use the Linux mv command. There are a few different options you can use with the Linux mv command, but I normally don’t use them. I do use the Linux mv command along with other commands to accomplish some tasks though. If you wanted to get information on the other
options for the Linux mv command, remember you can always run man mv in a bash shell prompt.
The usage of the Linux mv command to move files around on your file system is much like the Linux cp command, but the source will no longer exist. To use the mv command in Linux shell, just run mv [source] [destination].
So for example I am making a new account on another Linux computer. I want to move my home directory to the new Linux computer. So first I setup nfs and mount my new Linux computer’s/home directory on my old Linux computer. Now I will run mv /home/max /mnt/home/ so all of my files move to my new Linux computer. This is just an example as I would most likely use rsyncLinux command to do this. Which I will go over in another Linux tutorial.
I have also seen a few Linux beginners having trouble moving files in Linux that have special characters in them. So to move files with special characters in Linux you will simple escape the characters that hold special meanings, like a space, (, or ). So for example I have a file named DSC06540 (New LCD TV).JPG this is an ugly filename but to move this file from my compact flash drive on my camera to my/home/max/images/electronics directory, I would simple escape all the special characters with a \ like this mv /media/CF/DSC06540\ \(New\ LCD\ TV\).JPG /home/max/images/electronics/
Another command I use quite often with the mv shell command isfind. I can have find search for files on my computer and move the files to a new location. To do this there are 2 methods you can use, one method of using Linux find to move files is a small script, for example if I want to move all my php files to /home/max/htdocs/I would run this: for i in `find *php`; do mv $i /home/max/htdocs; done.
Method 2 that uses Linux find command to move files in Linux is using the -exec option of find to execute mv. This command was brought to my attention a few days ago by another Linux user, and it is much faster than my method. Using the same example to move my php files, but using this method, you will run: find *php -exec mv {} /home/max/htdocs \; which is a lot less to type!
You can also change your find options any way you prefer to search your hard drive for the files you are looking for. Which I will go over in another Linux tutorial.
As you can see it isn’t hard at all to move files and folders in Linux shell prompt at all. As always I hope this Linux tutorial for beginners has helped you learn more about the Linux mv command. I hope you come back and find more help on Beginner Linux Tutorial.
options for the Linux mv command, remember you can always run man mv in a bash shell prompt.
The usage of the Linux mv command to move files around on your file system is much like the Linux cp command, but the source will no longer exist. To use the mv command in Linux shell, just run mv [source] [destination].
So for example I am making a new account on another Linux computer. I want to move my home directory to the new Linux computer. So first I setup nfs and mount my new Linux computer’s/home directory on my old Linux computer. Now I will run mv /home/max /mnt/home/ so all of my files move to my new Linux computer. This is just an example as I would most likely use rsyncLinux command to do this. Which I will go over in another Linux tutorial.
I have also seen a few Linux beginners having trouble moving files in Linux that have special characters in them. So to move files with special characters in Linux you will simple escape the characters that hold special meanings, like a space, (, or ). So for example I have a file named DSC06540 (New LCD TV).JPG this is an ugly filename but to move this file from my compact flash drive on my camera to my/home/max/images/electronics directory, I would simple escape all the special characters with a \ like this mv /media/CF/DSC06540\ \(New\ LCD\ TV\).JPG /home/max/images/electronics/
Another command I use quite often with the mv shell command isfind. I can have find search for files on my computer and move the files to a new location. To do this there are 2 methods you can use, one method of using Linux find to move files is a small script, for example if I want to move all my php files to /home/max/htdocs/I would run this: for i in `find *php`; do mv $i /home/max/htdocs; done.
Method 2 that uses Linux find command to move files in Linux is using the -exec option of find to execute mv. This command was brought to my attention a few days ago by another Linux user, and it is much faster than my method. Using the same example to move my php files, but using this method, you will run: find *php -exec mv {} /home/max/htdocs \; which is a lot less to type!
You can also change your find options any way you prefer to search your hard drive for the files you are looking for. Which I will go over in another Linux tutorial.
As you can see it isn’t hard at all to move files and folders in Linux shell prompt at all. As always I hope this Linux tutorial for beginners has helped you learn more about the Linux mv command. I hope you come back and find more help on Beginner Linux Tutorial.
Subscribe to:
Posts (Atom)