Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Thursday, September 26, 2013

How to replace string in the project using terminal in Ubuntu?

We want to replace the string "regexp" with the string "replacement" in the terminal.
Let's say our project path is /home/www/project_name.
Actually regexp string is a regular expression pattern for our string.

This command works right:
cd /home/www/project_name
find . -type f -print0 | xargs -0 sed -i 's/regexp/replacement/g'
Let's see what the command means.
I will translate it to the normal language for human beings.

Go to my project folder:
cd /home/www/project_name Find all files (-type f) in my project folder:
find . -type f Use \0 delimiter (and not whitespace) to separate between the found pathnames in the output.
(We don't want whitespaces, because filenames can contain whitespaces and we will not be able to separate between pathnames).
-print0 This is a pipe. It means all the output that we have got before this sign "|" becomes an input for a next command (xargs in our case).
| xargs takes the output (pathnames that the command find found).
We use -0 because pathnames are terminated by \0 (instead of by whitespace). We know because we specified (find -print0).
xargs -0 sed - stream editor for filtering and transforming text.
-i allows to edit files in place.
-g replace all matches, not just the first match.
Replace our "regexp" with "replacement". sed -i 's/regexp/replacement/g'

Tuesday, February 26, 2013

Some useful BASH shell hot keys and useful tips.

Check out these hot keys. They can help a lot to save your time.
Since I started using them, I'm just a new man :)

This one is so important, that I'll write it separately.
Ctrl+R To search in previous commands. It displays the last occurrence.
Ctrl+R+R It displays the occurrence before the last.

These commands are also very useful. When I say they are "useful", I really mean that I use them! :)
Ctrl+K To delete the characters from the cursor to the end of the line.
ESC+D To delete the characters from the cursor position to the end of the word
Ctrl+A To move the cursor to the beginning of the command line
Ctrl+E To move the cursor to the end of the command
Ctrl+L To clear the screen, puts the current command line at the top of the screen

And I've got one additional tip for you. Use aliases!
Don't be lazy. It's so worth it!
To create your own alias, edit the file ~/.bashrc. Put there your alias.
Here is my alias that I use very frequently:
 alias pr='cd /var/www/myprojects' 
In this file you can see already added aliases. To check them out, you can also use alias command.

Saturday, February 16, 2013

Some basic UNIX commands

Today I will write down some basic UNIX commands.
"cd -" will switch you to the previous directory.
testuser@test:~/Downloads$ cd ../Desktop/
testuser@test:~/Desktop$ cd -
/home/testuser/Downloads
testuser@test:~/Downloads$ 

"cd ~" or "cd" will switch you to your home directory.
testuser@test:~/Downloads$ cd ../Desktop/
testuser@test:~/Desktop$ cd -
/home/testuser/Downloads
testuser@test:~/Downloads$ 

"pwd" (print working directory) is used to output the path of the current working directory.
testuser@test:~/Desktop$ pwd
/home/testuser/Desktop

Friday, September 14, 2012

How to find files in a directory hierarchy that contain a string in Ubuntu

find . | grep 'string'
Search for files that contain string "string".

Wednesday, September 12, 2012

How to get the url of the current repository

git config --get remote.origin.url

Sunday, September 11, 2011

What php.ini file is used by console

If you are not sure about what php.ini file is used by console, you can find out that by some methods. There is one of them. You can do it by parsing information about php, that will be displayed by php -i.
php -i | grep php\.ini
or
find / -name php.ini 

Monday, April 25, 2011

Структура корневого каталога системы Ubuntu

Во-первых, корневой каталог / это папка File System.
Во-вторых, значок ~, то есть тильда, это домашняя директория пользователя.

Дальше идет не мое описание. Взято отсюда http://myubuntu.ru/faq/struktura-fajlovoj-sistemy-ubuntu/

Мне удобно, чтобы было под рукой, в связи c моим переездом на Ubuntu.

Структура файловой системы Ubuntu очень сильно отличается от структуры Windows. И у новых пользователей, на первых порах, при переходе с Windows на Ubuntu, возникает много вопросов. Рассмотрим, что хранится в том или ином каталоге.