Linux/Magento: Daily useful development commands
These are the daily commands I use at work. This will definately help someone who is not familiar with all these commands in Linux and Magento.
Linux: Search / Replace recursively
find /path/here/ -type f -exec sed -i ‘s/search string/replace string/g’ {} \;
Linux: Find all files matching a string
grep -r “string to search” /path/to/search/
Linux: In vi editor, copy/paste/delete/replace/insert/save/undo/redo/search-replace/goto
Open file: vi filename
Copy: yy (yank) (for multiple lines copy, 5yy – for copying 5 lines)
Paste: p
Delete: dd (for multiple lines delete, 5dd – for deleting 5 lines)
Replace: r (on character you wish to replace, press r and enter new character)
Insert: i or insert key
Save: escape and : x (without space between : and x) (x = write and quit, w = write, q = quit, q! = quit without saving)
Undo: u
Redo: Ctrl+R
Search: escape key THEN / THEN write string to find THEN enter
Search-Replace: :%s/search string/replacement string/g
Goto Line number: escape key THEN : THEN line number (e.g. :22 to go to 22nd line of current file)
Linux: Search previous execute command in terminal
in terminal, press Ctrl+R and type few characters.
This will show you previous command matching that sequence of characters
To check another command matching same characters, press Ctrl+R again
Linux: Recursively change files/directories permissions
find . -type d -exec chmod 0755 {} \;
find . -type f -exec chmod 0644 {} \;
owner / read (4) + write (2) + execute (1)
group / read (4) + write (2) + execute (1)
world / read (4) + write (2) + execute (1)
Linux: Show unique values of any column in CSV
cat file.csv | cut -f 1 -d , | sort|uniq -c | tee tempfile
here, 1 = 1st column, which can be changed to view any column
uniq -c = unique values with count of occurences of each value. You can omit -c to just see the unique values
file.csv = filename, you can have any file here with any extension
, = delimiter used to separate columns
tee tempfile = moves the output to file “tempfile”
Linux: Recursively change ownership of directories/files
chown -R www-data:www-data magento
-R = for recursive
www-data:www-data = change owner to www-data (apache)
magento = directory to change permission for, recursively
Linux: Remove all Magento cache files
From your magento root in terminal, execute this:
rm -rf var/cache/*
DON’T put any space after cache/ and *, otherwise it will delete your WHOLE magento project 😀
To delete all the active sessions on your magento store,
rm -rf var/session/*
Continue reading »
Mysql root password reset or create
Mysql root password reset easily by following below instructions. For those who want to create (if no root user in mysql) or reset the password for the Root user in Mysql (in Linux), this post is definately going to help you. I had a tough time in getting this to work, so thought to share it with anyone facing the same problem.
You need to use –skip-grant-tables if you don’t know mysql password to login. You can use it like this:
/usr/bin/mysqld_safe –skip-grant-tables &
Once you run the above command on terminal, write mysql and hit enter. That’s because you already said Mysql that you want to skip all the privileges checking and allowing you with all the database access without password.
You should be inside mysql now. Now execute the command use mysql; because we are going to create/change the user in “mysql” database.
Continue reading »
Linux: Bash script to check availability of domain names in differnet TLDs
If you want to check whether your desired domain name is available or not in different extensions, it’s tiresome to search it for each and every tld. There are also limits of performing query to whois on websites, where they will not allow you unlimited whois information queries. It’s better to have your own script which will tell you the availibility of domain name in different extensions, right from your terminal.
Below script will check your domain name for TLDs .com, .net, .org, .info, .us, .co, .tel, .tv, .biz, .cc, .ru, .eu, .in, .it, .sk, .com.au, .sh, .re and .dk
But you can add other TLDs also if you want.
First create a file, e.g. chkWhois.sh, and give it proper permission to execute.
touch chkWhois.sh | |
chmod 744 chkWhois.sh |
Now, copy below code to this newly created file
Continue reading »
Linux: Bash script to get email address and created/updated/expires dates of domain name
In linux, to check the whois of any domain name, the simple command is:
whois domainname.com |
But, it will show you so many things which are not important, e.g. it will show you the NOTICE and TERMS of USE and so many other things.
If you are only concerned of getting the email address and creation/updation/expiry date of domain name from whois, here is the bash script that will help you out.
First create a bash script file, e.g. whoisEmailAndDates.sh and give it permissions to run:
touch whoisEmailAndDates.sh | |
chmod 744 whoisEmailAndDates.sh |
Ubuntu: Delete temporary/cache files
It’s necessary to clean unnecessary files from your operating system and free up space. In Ubuntu, this is very easy if you have admin privileges.
Below command will remove all the unnecessary package files, which are no longer used by their packages. You can say they are orphaned files, not needed anymore.
sudo apt-get autoremove
Below command will remove all the cache and unnecessary files from your system. It will delete everything and make your system clean from temporary files and orphaned files.
sudo apt-get clean
Welcome to my Blog
Certifications
Honor
Recognition
Contributions
Categories
- Apache (2)
- ChatGPT (1)
- Domain name (2)
- eCommerce (2)
- htaccess (1)
- Humor (3)
- Instagram API (1)
- jQuery (4)
- JSON (1)
- Linux (10)
- Magento (142)
- Magento admin (58)
- Magento Certification (5)
- Magento error (13)
- Magento frontend (68)
- Magento Imagine (2)
- Magento Interview (5)
- Magento Master (2)
- Magento2 (10)
- Mobile (1)
- MySQL (7)
- OpenAI (1)
- OroCRM (2)
- Performance (2)
- PHP (8)
- Prototype JS (3)
- Security (4)
- Wordpress (3)
- XML (2)