Archive for category Shell

Linux chmod 777 Recursively

There are times that you want to set permission for a folder of files. It’s very tedious to change every single file, so you must ask: is there a way to chmod a folder recursively, so that all files in a folder or directory can be set to writable by one command? Well, the answer is: Yes. There is a way and it’s very simple. There is a recursive chmod

chmod -R 777 /home/shi/Desktop/Host/lab/txp

The above code will set permission for all files under /home/shi/Desktop/Host/lab/txp directory, you can change it to anything you may like to point to.

Hope this helps!

1 Comment

Unix Shell Command Line Tips

There are two major time-savers when dealing with long files on the command line (Unix Shell) : file globs and tab completion. File globs are symbols you can use as wildcards in the place of a filename. You can substitute the ? symbol for any single character in a filename, and * for any number of characters in a filename. For instance, say you had three files: car, bus, and cab. If you wanted to delete both car and cab, you would type:
rm ca?

The ? matches both r and the b at the end of the filename. If you wanted to remove all files that started with the letter b, you would type:
rm b*

Tab completion is another time-saver on the command line. If you start to type a command and then hit the Tab key, the shell will automatically attempt to complete the name of the command for you. In the case that more than one command matches what you have typed so far, hit Tab an extra time, and you will be shown all of the options that match:

apt-get followed by hitting the tab key twice.

Tab completion also works for files and directory names. Just type the first part of the filename and hit Tab, and the shell will fill out the rest for you.Once you are finished with a terminal, you can close the window like any other window, or, alternatively, you can type exit on the command line.

No Comments

Manipulate Files Directories using Unix Shell

This article continues from the previous article about using Unix Shell (command line) to operate Unix-like operating systems like Linux Ubuntu. We will see how to use Unix Shell to create, rename, move and delete files and directories.

To create a directory from the command line, type the mkdir command followed by the name of the directory, let’s create a directory called bollocks
mkdir bollocks

Use the mv command to move a file or directory to a different directory, or to rename it in its current directory. To rename the bollocks directory you created to sex_pistols you can use:
mv bollocks sex_pistols

If you wanted to move the sex_pistols directory inside the Desktop directory, you would just specify the Desktop directory as the second argument:
mv sex_pistols Desktop/

The rm command removes files, and rmdir removes directories. Just use the commands followed by the files or directories to remove, respectively:
rm Desktop/sex_pistols/
bodies.mp3
rmdir Desktop/sex_pistols/

You can also remove a directory and all files and directories inside of it by running rm -r followed by the name of the directory.

Notice: Be careful when you recursively delete a directory with this command that you do in fact want to remove all of the files within. Once removed via the command line, there’s no trash bin to retrieve them from.

1 Comment

Navigate the Filesystem using Unix shell

Due to the popularity of mainstream operating systems, desktops like Windows or Mac, the command line might seem like a foreign thing to many people. Typing commands into a window might seem, well, arcane. But even though Linux has really progressed on the desktop, there is still a lot of power you can wield at the command line. So if you are a former Windows or Mac user and recently joined the ‘free and open source revolution’ but suddenly feel lost in this utopia (can’t get used to the command line), I think you should take a deep breathe and take a bit of time to learn this powerful technology. Knowledge is power, once you get this power, you will find that you have so much freedom to think and act independently, no longer rely on soul-sucking evil cult companies like Microsoft or Macintosh.

The most popular Unix-like computer operating system would be Linux, there are many well-known Linux distributions like Fedora, openSUSE, Ubuntu etc. The most well-known among all these is Ubuntu. So now let’s see how we can navigate the filesystem on Ubuntu using Shell script.

The first step is to launch a terminal. Click Applications > Accessories > Termial to start default GNOME (GNOME is one of the three most popular uer interfaces on desktop machines, the other two are KDE and Xfce) Terminal program.

Now that the terminal program is open, you can navigate the filesystem. By default, terminals will open your home directory, so one thing you might want to do is see what files are currently in your home directory. The ls command displays all the files in the directory you specify (or in the current directory if you don’t list a drectory):
ls

The command above will display all the files in the home directory

To get the list of contents on the Desktop directory, type the following command:
ls Desktop/

Notice: please take note that in the Unix world, all directory and file names are case-sensitive. So if you change the above command to: ls desktop/, you will end up getting a response like: No such file or directory.

If you want to navigate to a certain directory, use the cd commond followed by the directory to change to:
cd Desktop/

You can use the pwd command to see where you currently are, to use it simply type: pwd

Tip: The ~ symbol is shorthand in Linux for your user’s home directory. If you type cd ~ you will automatically change back to your home directory. It saves you from having to type out cd /home/ username.

Hope this helps!

No Comments

PHP – Unzip File from Browser

I won’t pretend to be an expert, but I thought I’d save the next person the grief of going through the SSH dramas again. Many people who have experience upload an entire site from localhost to remote server knows it really really take a while to upload a gazillion files at once. Professionals use SSH clients to do this task. They first zip all the files up, upload through FTP (which is much faster than upload an uncompressed folder), and unzip it using SSH client. But if you are one of the folks who is new to IT and just want a quick and dirty way to do it without knowing what the heck is SSH. Here is a quick and dirty way for you. Step 1: Write a PHP file called unzip.php with the following line of code in it (yes, you hear me right, only one line of code) : exec(”unzip myentiresite.zip”); Step 2: After you have created the unzip.php, zip your entire site up, and name it myentiresite.zip or whatever name you want that correspond to the file name in the PHP file. Step 3: Now upload both the ZIP file and the unzip.php file to the remote server. Step 4: From your browser, point to the URL your unzip.php is located at. And you are done, refresh your FTP client, and your should be able to see the decompressed files.

3 Comments